Python Webdriver Selenium HELP !

Im using Python Webdriver Selenium for web scraping i know it is not the best way to scraping , anyway when i used ID to get page text some blocks that includ text did not copy its seems to locked i want to unlock it , im not interface with stable page that can you edit HTML manualy im using code to put some digit that give me a result which copy it then reply this prosses with new digit after copyed the last text result with “while” and so on .

This is the code 

username=2000234361

while (username<2000234371):
driver.find_element_by_id(‘txtNatID’).send_keys(username)
driver.find_element_by_id(‘btnSearch’).click()
name=driver.find_element_by_id(“txtNameAR”).text
name_en=driver.find_element_by_id(“txtNameEN”).text
username+=1
print(username-1,"*",name,"*",name_en)
driver.find_element_by_id(“txtNatID”).clear()

1 Like

I’m having difficulty following what you are trying to accomplish and what the problem(s) are.

I _think_ the first problem you say you are having is this line:

name_en=driver.find_element_by_id("txtNameEN").text

does not work because the “txtNameEN” field is disabled. Some googling suggests you might try the “value” property, such as:

name_en=driver.find_element_by_id("txtNameEN").value
2 Likes

Unfortunately it didn’t work

Traceback (most recent call last):
File “<stdin>”, line 4, in <module>
AttributeError: ‘WebElement’ object has no attribute ‘value’

1 Like

OK, try:

driver.findElement(By.id("write_element_id_here")).getAttribute("value");

substituting “write_element_id_here” appropriately.

Not a Selenium expert, merely googling “selenium disabled text field”.

2 Likes

Also it did not work :

AttributeError: ‘WebElement’ object has no attribute ‘getAttribute’

Most of Selenium tutorials on java nor python

1 Like

Whelp, my Selenium ignorance is showing.

This suggests it is “.get_attribute(‘value’)”, not “.getAttribute(“value”)”.  Which is confirmed by the docs.

3 Likes

Finally it is work !!

Thank you

1 Like