Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait and get value of Span object in Selenium Python binding

I have following code in my web page.

<div id="" class="user_acc_setails">
<ul id="accDtlUL">
<li>First Name: <span id="f_name">Anuja</span></li>

By the time page loading, the value for Sapn is not set. It will take very small time to set the value. I want to wait and get that value in my Python file.

I'm currently using following code,

element = context.browser.find_element_by_id('f_name')
assert element.text == 'Anuja'

But it gives me an AssetionError. How can I solve this?

Thanks

like image 853
AnujAroshA Avatar asked Sep 04 '13 07:09

AnujAroshA


1 Answers

Correct way it this case would be to use Explicit waits (see Python code there). So you need something like

from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.text_to_be_present_in_element((By.Id,'f_name'), 'Anuja'))
like image 189
Petr Mensik Avatar answered Sep 28 '22 07:09

Petr Mensik