gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:09:00 24 4
gpt4 key购买 nike

我最近开始使用 Selenium 来测试具有 WebView 的应用程序。那么我的 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 - 使用带有 Ruby 的 Selenium Webdriver 的 css 选择器/xpath 查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17932696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com