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.

Kishan Patel
  • 1,385
  • 3
  • 13
  • 24
dizwe
  • 71
  • 2
  • 10
  • please read this http://stackoverflow.com/questions/17533024/how-to-set-selenium-python-webdriver-default-timeout – Vivek Maru Apr 05 '17 at 06:13
  • why not just `import time` and set `time.sleep(3.6)` before `driver.execute_script('scroll(0, 300);')`? – Andersson Apr 05 '17 at 06: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. – dizwe Apr 05 '17 at 07: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. – dizwe Apr 05 '17 at 07:25

1 Answers1

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

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • 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")))` – dizwe Apr 07 '17 at 02:30