Reputation: 405
Scenario:
There is a text in my webpage
I am using xpath to locate it
myxpath=//table[@id='table44']/tbody/tr[1]/td[1]/span[2]
I am trying to get it value using
value=driver.find_element(:xpath, myxpath).text
But problem is :sometimes it gets value & sometime it doesn't & i am not able to understand the cause of this problem
Any alternative that i can try ?
Upvotes: 1
Views: 323
Reputation: 118271
You can write using explicit wait
.
my_xpath = "//table[@id='table44']/tbody/tr[1]/td[1]/span[2]"
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
element = wait.until { driver.find_element(:xpath, my_xpath) }
puts element.text
Upvotes: 1