简体   繁体   中英

Get element value in Selenium webdriver ruby script

I am trying to put some asserts by getting value and then comparing them. But, the get value statement always returns nil.

Desired value:-

<span class="contractSalesPrice.contractSalesPrice">$314,507.30</span>

I tried following ways: -

element1 = browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span")

browser.execute_script("return arguments[0]", element1)

browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").attribute('value')

browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").value

What could be wrong?

Pls help, Thank You in advance.

Abhishek

You need to use #text method.

browser.find_element(:css,"#total > tbody > tr > td:nth-child(4) > span").text

attribute method is used to get the value of attributes of HTML elements. In your case, there is no attribute called 'value' in span element, thus the method returns nil . For more information read the documentation I linked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM