使用带有Ruby的Selenium Webdriver的css selector / xpath查找元素 [英] Find elements using css selector/xpath of Selenium Webdriver with Ruby

查看:1025
本文介绍了使用带有Ruby的Selenium Webdriver的css selector / xpath查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用Selenium测试具有网页浏览功能的应用程式。我的webview的代码是:

I have recently started using Selenium to test an app having webviews. Well the code for my webview is:

<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"> 

我正在编写一个可重复使用的代码来找到自动化测试的元素。在上面的代码中,元素可以使用2种方式找到,我可以基于'dd:concept =TITLE'或通过文本This is TITLE;但我找不到任何东西在Selenium使用它可以找到的元素我想要的方式。

I am writing a re-usable code to find the element for automation testing. In the above code, element can be found using 2 ways, I can look for it based on 'dd:concept="TITLE"' or through the text "This is TITLE"; but I could not find anything in Selenium using which I can find the element the way I want to.

我使用find_element来寻找一个元素,但有是不是我可以通过'dd:concept =TITLE'这是TITLE

I am using "find_element" to look for an element, but there is nothing to which I can pass 'dd:concept="TITLE"' or "This is TITLE" as an arguement.

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

使用Selenium驱动程序和一些文本作为其参数的webview上的元素

Is there anyway I can find the element on the webview using Selenium driver and some text as its arguement??

推荐答案

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

FindElement(By.CssSelector("[dd:concept='TITLE']")) should work.

啊,你用的是ruby。

Ah, you're using ruby.

我做了一些查找,你可以尝试这样:

I did a bit of looking, you could try this:

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

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

再次编辑。

我建议在标签名称dd:concept中转义:

I would suggest escaping the : in the tag name dd:concept, like this:

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

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

这篇关于使用带有Ruby的Selenium Webdriver的css selector / xpath查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆