Selenium Webdriver获取自定义属性值

时间:2022-11-27 16:47:01

How can i get value of custom attribute ('173136' from data-id and 'NORMAL' from data-status for example) inside of div using Selenium Webdriver in ruby?

如何在ruby中使用Selenium Webdriver获取div内部的自定义属性(来自data-id的'173136'和来自数据状态的'NORMAL')的值?

<div class="trow " data-id="173136" data-status="NORMAL" data-running="false">

I found that watir-webdriver can afford that https://jkotests.wordpress.com/2012/11/23/get-attribute-values-of-the-html-element/, but as I mentioned we are using selemium-webdriver. Any suggestions?

我发现watir-webdriver可以承受https://jkotests.wordpress.com/2012/11/23/get-attribute-values-of-the-html-element/,但正如我所提到的,我们正在使用selemium-webdriver 。有什么建议么?

1 个解决方案

#1


3  

It's very easy, just:

这很容易,只是:

browser.div(somes identificator like :xpath or :text).data_id
browser.div(somes identificator like :xpath or :text).data_status

But, yes, it's for Watir..for selenium it's somes like:

但是,是的,它适用于Watir ..对于硒,它有些像:

driver.find_element(:xpath, "some xpath").attribute("data-id")
driver.find_element(:xpath, "some xpath").attribute("data-status")

#1


3  

It's very easy, just:

这很容易,只是:

browser.div(somes identificator like :xpath or :text).data_id
browser.div(somes identificator like :xpath or :text).data_status

But, yes, it's for Watir..for selenium it's somes like:

但是,是的,它适用于Watir ..对于硒,它有些像:

driver.find_element(:xpath, "some xpath").attribute("data-id")
driver.find_element(:xpath, "some xpath").attribute("data-status")