2

I have encountered a problem using selenium with python. I'm trying to interact with a page like this:

driver_window_manager.get(url)
iframe = driver_window_manager.find_elements_by_tag_name('iframe')[0]
driver_window_manager.switch_to_frame(iframe)

But in the WebPage, a popup appears and waiting for the user to click AND THEN the page finally loads.

But driver.get in selenium waits for the page to be fully load, so i can't close this popup and interact with the page.

Thank you everyone and sorry for my poor english.

Shivam Mishra
  • 1,731
  • 2
  • 11
  • 29

2 Answers2

1

driver.get waits for the page to be loaded and then only proceeds further, if you don't want to wait, then you need to use javascript to load the URL with execute_script. It returns immediately so that you can perform any actions you want -

driver.execute_script("window.open(your_url);")

Now, if you want to, for example accept a popup, you can do -

WebDriverWait(driver, 10).until(EC.alert_is_present())
alert = driver.switch_to.alert
alert.accept()

Note, you need to add the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Shivam Mishra
  • 1,731
  • 2
  • 11
  • 29
  • execute script doesnt work it returns me a "unknown error" :ile "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token – vandaele mathias Aug 03 '18 at 08:07
  • Is that normal that driver.execute_script("window.open(your_url)") works but its blocking my code until the page is loaded .. – vandaele mathias Aug 03 '18 at 09:07
  • @vandaelemathias you need to add a ";" at the end of js command. I have updated the code, try that and tell me what happens – Shivam Mishra Aug 03 '18 at 09:16
0

The blocking behaviour you describe is because of the default page load strategy in Selenium. You can alter this via the desiredCapabilities or options class for your chosen browser.

InternetExplorerOptions ieOptions = ieOptions();
ieOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
driver = new InternetExplorerDriver(ieOptions);
Harry King
  • 502
  • 4
  • 15