selenium-webdriver - 如何使用 CSS 选择器选择链接文本?

标签 selenium-webdriver css-selectors

我有一个包含更多行的表格,我需要查找特定的“selecttext1”。 -class myclass 是不够的,因为它用于每一行 -href="#/test/id_var1 每次都在变,我不知道它的值

<td class="myclass">
<a class="ng-binding" href="#/test/id_var1">selectthistext1</a>
</td>

<td class="myclass">
<a class="ng-binding" href="#/test/id_var2">selectthistext2</a>
</td>

最佳答案

您可以使用 linktext 或 xpath 如下:

driver.findElement(By.xpath("//a[text()='selectthistext1']"));
//OR
driver.findElement(By.linkText("selectthistext1"));

你也可以看看答案:Need to find element in selenium by cssWriting cssselector expression for webDriver using attribute matching

关于selenium-webdriver - 如何使用 CSS 选择器选择链接文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21575965/

相关文章:

html - 如果元素在父元素中只出现一次,则将 CSS 规则应用于该元素

css - 是否有 "previous sibling"选择器?

c# - 无法正确导航到 Selenium webDriver 2.0b3 IE 和 chrome 中的 url

java - 无法返回 href 的文本值

php - 使用 PHP 在 Selenium WebDriver 上远程上传文件

xpath - 网页抓取选择器

html - "display: contents"属性值是如何工作的?

html - 当父 div 有多个类时定位嵌套 div

java - 无法单击选项卡的子值,在 Selenium 中出现 'element not visible' 异常

python-2.7 - 如何计算 Selenium Python 中元素的属性数?