Ravi Yadav
Ravi Yadav

Reputation: 405

Selenium webdriver ruby: Unable to read text value some times

Scenario:

  1. There is a text in my webpage

  2. I am using xpath to locate it

    myxpath=//table[@id='table44']/tbody/tr[1]/td[1]/span[2]
    
  3. 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

Answers (1)

Arup Rakshit
Arup Rakshit

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

Related Questions