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
Selenium 探索我前进的道路_Selenium_Xpath - Fatal编程技术网

Selenium 探索我前进的道路

Selenium 探索我前进的道路,selenium,xpath,Selenium,Xpath,我使用的是selenium的webdriver。通过链接文本(“searchterm”)查找元素以获取webElement。然后,我可以通过使用webElement.get_属性('href')和'href'找到href值,我可以通过xpath找到元素本身: .//*[@href=webElement.get_attribute('href')] 问题是,这不是我要单击的链接,我要单击的链接有“google reader”文本,并且在下面三列: <tr id="AB2Xq4gXoer9s

我使用的是selenium的
webdriver。通过链接文本(“searchterm”)查找元素以获取webElement。然后,我可以通过使用
webElement.get_属性('href')
和'href'找到
href
值,我可以通过xpath找到元素本身:

.//*[@href=webElement.get_attribute('href')]
问题是,这不是我要单击的链接,我要单击的链接有“google reader”文本,并且在下面三列:

<tr id="AB2Xq4gXoer9sCEEr-rRcZjVz1p021-gdypaX-U" class="ACTIVE">
  <td class="checkbox">
    <td class="alert-type" colspan="2">
      <a href="RETRIEVABLE ATTRIBUTE">FOUND TEXT</a>
    </td>
    <td class="alert-volume">Only the best results</td>
    <td class="alert-frequency">As-it-happens</td>
    <td class="alert-delivery">
      <a href="THE ELEMENT I WANT TO CLICK">Google Reader</a>
      <a href="another link">
    </td>

只有最好的结果
碰巧
这里的问题是有一系列的“谷歌阅读器”链接,所以这个词不能使用

有没有可能通过路径导航到我想要的元素/链接

我一直在试着去找父母,然后去找合适的孩子,但我就是没能做到

感谢您给予的任何时间和帮助


真诚地将
a
text()
与字符串进行比较:

//a[text()=“谷歌阅读器”]
要从找到的文本获取相应的
谷歌阅读器
,请使用
(父项)和
以下同级项

//a[text()=“FOUND text”]/../following sibling::td/a[text()=“Google Reader”]

好吧,我会尝试以下方法:

String xPathLink="//a[contains(text(),'Google Reader')]"
    List<WebElement> a=driver.findElements(By.xpath(xPathLink));


      a.get(0).click();
//or         a.get(1).click();
//or         a.get(2).click();
String xPathLink=“//a[contains(text(),'Google Reader')”
列表a=driver.findElements(By.xpath(xPathLink));
a、 获取(0)。单击();
//或a.get(1)。单击();
//或a.get(2)。单击();
它取决于包含“Google Reader”的元素列表中的顺序

好的,firebug会给你一个关于你需要点击的元素的提示。

在本例中,“搜索词”是什么?+1根据提供的信息应该可以工作。但我认为这会有点复杂:)@choroba没那么容易不幸的是,页面上有一长串“谷歌阅读器”链接