3

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()
4
  • hard to know without seeing some code Commented Jul 22, 2014 at 21:45
  • I added some more code... Commented Jul 23, 2014 at 16:01
  • 3
    Try to change driver.find_element_by_id('ctl00_Top_EntryButton').click() by driver.execute_script("setTimeout(function () { document.querySelector(\"#ctl00_Top_EntryButton\").click() }, 1000);"). This does the same but by injected JavaScript. Because it delay execution by 1 sec, and JS execution as asynchronous, rember to add sleep call. In my case problem was caused because the clicked button closed window and Selenium was waiting for page load after click (and some other actions). Wait for page load after window close cased infinite loop in selenium "core". Commented Oct 6, 2017 at 19:37
  • @Misaz thank you. Without your answer, I couldn't complete my project. I was stuck on this. Commented Jun 5, 2024 at 2:24

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

This helped me:

from selenium.webdriver import DesiredCapabilities

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

driver = webdriver.Firefox(capabilities=capabilities)

....click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.