Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为此创建适合Selenium的XPath?_Selenium_Xpath - Fatal编程技术网

如何为此创建适合Selenium的XPath?

如何为此创建适合Selenium的XPath?,selenium,xpath,Selenium,Xpath,请帮助我为以下内容创建Xpath。我使用的是SeleniumWebDriver,只有IE浏览器。以下是HTML: <A title="" href="javascript:Plg({u:'/epace/starintfc.html?module=RUN_EVENT',p:0,nw:'0'});" p="eagle/pace/pace" la="" ml="%09NULL%09PLUGIN%09%2fepace%2fstarintfc.html%3fm

请帮助我为以下内容创建Xpath。我使用的是SeleniumWebDriver,只有IE浏览器。以下是HTML:

<A
    title=""
    href="javascript:Plg({u:'/epace/starintfc.html?module=RUN_EVENT',p:0,nw:'0'});"
    p="eagle/pace/pace"
    la=""
    ml="%09NULL%09PLUGIN%09%2fepace%2fstarintfc.html%3fmodule%3dRUN_EVENT%09%09%09%09%09%09%09%09%09%09"
    t="Plugin" gh="" g="Data Steward"
    pc="Eagle/PACE/PACE Components"
    ivname=""
><IMG id=Item.Img
      class=link
      src="/tpe/modules/site/img/menu_plugin.gif">Run An Event</A>

由于CSS比xPath简单,我更喜欢CSS,因此我将提供CSS和xPath解决方案:

请记住,您希望获得具有最特殊性的元素的属性。下面的答案是我最大的能力,以确定哪一个最具特异性。(如果您想进一步了解CSS和元素的特殊性)

如果您试图选择第一个
元素

CSS: xPath: 如果您试图选择
标记内的

CSS: xPath:
我猜你想要第一个,因为它是一个链接,我假设你想点击它。

你特别想选择什么元素-链接还是图像?我们能看看你先尝试了什么吗?(我已经重新格式化了你的HTML,使它更可读)。你是对的,我正在尝试调用click.cool上的链接。让我知道这是否有帮助!如果它回答了您的问题,请继续并向上投票并接受我尝试了XPATH和CSS两种建议,结果如下:org.openqa.selenium.NoSuchElementException:找不到XPATH=//a[contains(@href,'RUN_EVENT')]的元素(警告:服务器没有提供任何堆栈跟踪信息)使用的命令持续时间或超时代码:String str=“//a[href*='RUN_EVENT']”;findElement(By.xpath(str)).click();看看源代码,这是一个
中的东西吗?是的,正如我所看到的,它是一个框架
a[href*='RUN_EVENT']
//a[contains(@href, 'RUN_EVENT')]
a[href*='RUN_EVENT'] > img
//a[contains(@href, 'RUN_EVENT')]/img