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

Testing 使用带有Ruby的Selenium Webdriver的css选择器/xpath查找元素,testing,css-selectors,selenium-webdriver,web-testing,ruby-test,Testing,Css Selectors,Selenium Webdriver,Web Testing,Ruby Test,我最近开始使用Selenium测试一个具有网络视图的应用程序。我的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

我最近开始使用Selenium测试一个具有网络视图的应用程序。我的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”
或通过文本
“这是TITLE”
查找它;但是我在Selenium中找不到任何我可以用我想要的方式找到元素的东西

我正在使用“find_element”查找元素,但没有任何内容可以作为参数传递给
'dd:concept=“TITLE”
“这是TITLE”

我尝试了-
driver.find_元素(:css,“span.class5”)
driver.find_元素(:css,“div.class1 class2 class3 class4 span.class5”)

是否仍然可以使用Selenium驱动程序和一些文本作为其参数在webview上找到元素???

findelelement(By.CssSelector(“[dd:concept='TITLE']”)应该可以工作

啊,你在用ruby

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

查找元素(:css,“[dd:concept='TITLE']”)

再次编辑

我建议在标记名dd:concept中转义:,如下所示:


查找元素(:css,[dd\:concept='TITLE'])

谢谢Richard!!但这对我帮助不大。我正在做$driver.find_元素(By.CssSelector(“[dd:concept='TITLE']”)及其给我的“NameError:uninitialized constant By from(pry):3:in`block(3 levels)in'”错误。我猜find_元素使用的唯一参数是这些参数之一-(:class,:class_name,:css,:id,:link_text,:link,:partial_link_text,:name,:tag_name,:xpath)我试过了。我收到“Selenium::WebDriver::Error::UnknownError:处理命令时发生未知服务器端错误。”Error通过一些google搜索,我发现我可以使用-driver.find_元素(:css,“div.ddsection ddrefreshable ddinsertfreetext ddremovable span.ddsection display”)。但即使这样对我也不管用,这对我管用。由于某种原因,我没有在dom中获得所需的文本,所以昨天它不起作用。