我是 Selenium C# 自动化的新手。尝试在网上查找但没有得到任何帮助。 html 代码如下所示。我需要找到该元素,然后使用 CSS 单击它。该站点仅在 IE 上运行。
<tbody>
<tr class="t-state-selected">
<td>Purchased</td>
<td class="">768990192</td>
最佳答案
我知道 Web 链接会消失,但这里有一些我在尝试弄清楚如何使用 Selenium 的 C# WebDriver 定位元素时使用的链接:
https://automatetheplanet.com/selenium-webdriver-locators-cheat-sheet/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors
https://www.packtpub.com/mapt/book/web_development/9781849515740/1
最重要的是,您可以按 ID、类或 XPath 进行选择。这些中的每一个都可以使用 F12 浏览器工具直接在页面上进行测试。例如,要找到对上述问题的第一条评论,您可以在控制台中尝试这样做:
$x("//div[@id='mainbar']//tbody[@class='js-comments-list']/tr")
Here's another SO post with a quick and dirty answer .
和here is the official documentation from Selenium on how to locate UI elements .
关于c# - 查找 Selenium C# 的 CSS 选择器路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47383732/