Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium webdriver hangs on element.click

I'm writing a script using Selenium's Python implementation. When the script reaches this line:

driver.find_element_by_id('ctl00_Top_EntryButton').click()

The page loads a modal dialog but the python script hangs on the command. I debugged it a little and it seems its stuck on a while loop in socket.py, I guess it's waiting for some input.

Does anyone have ideas on what's wrong?

EDIT
I'm adding some more code for clarity:

driver = webdriver.Firefox()
driver.get("https://www.somesite.com")
driver.switch_to_frame("mainIFrame")
driver.find_element_by_id('ctl00_Top_EntryButton').click()
like image 570
noamelf Avatar asked Dec 06 '25 03:12

noamelf


2 Answers

It's possible that by the time your program gets to the .click() function, the webpage hasn't loaded yet, and thus the click function might not work properly. Try adding a time.sleep(10) line or so to your function right before the .click() line and see if that solves the problem.

like image 59
jj172 Avatar answered Dec 08 '25 17:12

jj172


This helped me:

from selenium.webdriver import DesiredCapabilities

capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['pageLoadStrategy'] = 'eager'

driver = webdriver.Firefox(capabilities=capabilities)

....click()
like image 26
Vivek Naik Avatar answered Dec 08 '25 18:12

Vivek Naik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!