c# - 查找 Selenium C# 的 CSS 选择器路径

标签 c# css selenium

我是 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/

相关文章:

c# - 在默认浏览器中打开 YouTube 嵌入式播放器链接

css - webkit 中的列表样式图像 svg 更小

javascript - 使用 Node.js 创建网站

html - 如何在中心并排放置 2 个 iframe?

Selenium 与 WebDriver,有什么明显的优势吗?

c# - 如何正确阻止方法直到对象计数器> 0?

c# - 在 tabcontrol C# 中搜索标签页

selenium - 使用 Selenium 2 在页面上查找文本

selenium - 是否可以自动打开 Google Chrome devtools?

c# - 扩展方法 : IXmlLineInfo 出现问题