Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Mission Specialist Lvl 1
Message 1 of 7

Python Webdriver Selenium HELP !

Solved! Go to Solution.

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 .

 

ioot.jpg

 

 

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()

6 Replies
Commander Lvl 2
Message 2 of 7

Re: Python Webdriver Selenium HELP !

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

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Mission Specialist Lvl 1
Message 3 of 7

Re: Python Webdriver Selenium HELP !

Unfortunately it didn't work

 

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

Commander Lvl 2
Message 4 of 7

Re: Python Webdriver Selenium HELP !

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".

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Mission Specialist Lvl 1
Message 5 of 7

Re: Python Webdriver Selenium HELP !

Also it did not work :

AttributeError: 'WebElement' object has no attribute 'getAttribute'

Most of Selenium tutorials on java nor python

 

Solution
Commander Lvl 2
Message 6 of 7

Re: Python Webdriver Selenium HELP !

Whelp, my Selenium ignorance is showing.

 

This suggests it is ".get_attribute('value')", not ".getAttribute("value")".  Which is confirmed by the docs.

 

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Mission Specialist Lvl 1
Message 7 of 7

Re: Python Webdriver Selenium HELP !

Finally it is work !!

Thank you