0

HI I was trying to pause the execution of Selenium for seconds to wait for Modal popup to show. But time.sleep(5) didn't work using phantomJS (I've heard that PhantomJS do not support sleep). So I came up setTimeout.

driver.execute_script('setTimeout(function(){"scroll(0, 300);"}, 3600);') 

But It doesn't work even in the Chrome Selenium driver.

Even though driver.execute_script('scroll(0, 300);') works, I don't know how to execute setTimeout in the selenium.

4
  • please read this stackoverflow.com/questions/17533024/… Commented Apr 5, 2017 at 6:13
  • why not just import time and set time.sleep(3.6) before driver.execute_script('scroll(0, 300);')? Commented Apr 5, 2017 at 6:52
  • @Andersson I've tried it. But I can't use time.sleep(3.6). I need to wait for madal popup to show. When I use time.sleep(3), It raises 'Element is not currently interactable and may not be manipulated' error. When I got screen shot, modal popup do not show up. Commented Apr 5, 2017 at 7:23
  • @VivekMaru I already tried driver.set_page_load_timeout(10) , driver.set_script_timeout(3) and `driver.implicitly_wait(10)'. But It didn't work. Commented Apr 5, 2017 at 7:25

1 Answer 1

0

If you need to meet some specific condition, you might use ExplicitWait + ExpectedConditions, like:

from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

wait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "Specify css selector for your modal div")))
driver.execute_script('scroll(0, 300);')

*You can use any selector you like as By.XPATH, By.ID, etc

This code should allow you to wait (up to 10 seconds) until visibility of required element before executing script

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

1 Comment

I've tried the way you mentioned. But when I got screenshot, modal div didn't come out. WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//*[@id=\"teacher_booked_modal\"]/div/div/div")))

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.