testing - 使用 Selenium Webdriver 的 css 选择器/xpath 和 Ruby 查找元素

标签 testing css-selectors selenium-webdriver web-testing ruby-test

我最近开始使用 Selenium 来测试具有 webviews 的应用程序。我的 WebView 的代码是:

<div class="class1 class2 class3 class4" style="padding: 4px;" id="_6bd7b91a-214c-4075-b7db-dcaa08155e1a"> 
    <span class="class5" style="font-weight: bold; text-decoration: underline;">This is TITLE</span> 
    <div class="class6" dd:contenttype="content_type1" dd:concept="TITLE" id="_1d8c4490-d0c1-42ed-a93e-e92ca570dd32">
     <div class="class7"> 

我正在编写一个可重用的代码来查找自动化测试的元素。上面的代码中,元素可以通过两种方式找到,我可以根据 'dd:concept="TITLE"' 来查找。或通过短信"This is TITLE" ;但我在 Selenium 中找不到任何可以按照我想要的方式找到元素的东西。

我正在使用“find_element”来查找元素,但没有任何内容可以传递 'dd:concept="TITLE"'"This is TITLE"作为一个论据。

我尝试过 - driver.find_element(:css, "span.class5")driver.find_element(:css, "div.class1 class2 class3 class4 span.class5")

无论如何,我可以使用 Selenium 驱动程序和一些文本作为其参数在 webview 上找到该元素吗?

最佳答案

FindElement(By.CssSelector("[dd:concept='TITLE']")) 应该可以工作。

啊,你正在使用 ruby​​。

我查了一下,你可以试试这个:

find_element(:css, "[dd:concept='TITLE']")

再次编辑。

我建议转义标签名称 dd:concept 中的 :,如下所示:

find_element(:css, "[dd\:concept='TITLE']")

关于testing - 使用 Selenium Webdriver 的 css 选择器/xpath 和 Ruby 查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17932696/

相关文章:

javascript - 如何断言函数不会引发异常

javascript - 单元测试时模拟外部库的方法有什么意义?

检查客户端证书的 HTTPS 测试服务器

css - 有没有用 C 语言编写的 CSS 选择器引擎?

jquery选择器无法从隐藏字段读取

CSS重新计算第n个 child

python - 导入错误: No module named selenium cronjob Mac

ruby - 在不同环境中运行 Cucumber 测试

java - "Sign In"使用 Java 的 WebDriver 未单击 yahoo 邮件按钮

python - Selenium webdriver xpath 过滤