1

I have this code:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
# import org.openqa.selenium.Keys
import datetime
import time
import unittest



cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreProtectedModeSettings'] = True
cap['IntroduceInstabilityByIgnoringProtectedModeSettings'] = True
cap['nativeEvents'] = True
cap['ignoreZoomSetting'] = True
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
browser = webdriver.Ie(capabilities=cap, executable_path=r'C:\IEDriverServer_x64_3.150.1\IEDriverServer.exe')
browser.implicitly_wait(2)

browser.get("https://www.google.ro/?safe=active&ssui=on")


search_form = browser.find_element_by_xpath('/html[1]/body[1]/div[1]/div[1]/div[3]/div[1]/button[1]')
search_form.click()

Any page I try to open, a timeout error is returned after awhile:

Traceback (most recent call last):
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\unittest\case.py", line 60, in testPartExecutor
    yield
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\unittest\case.py", line 672, in run
    self._callSetUp()
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\unittest\case.py", line 630, in _callSetUp
    self.setUp()
  File "C:\Users\MunteanuG\PycharmProjects\Dex_Automation\SRC\utilityTools.py", line 24, in setUp
    self.browser.get("https://www.google.ro/?safe=active&ssui=on")
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\MunteanuG\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load.

I am using python 3.7 interpretator. Post mostly code, adding text to post, test test test test

Henry-G
  • 131
  • 1
  • 8

2 Answers2

1

It seems like the page you are trying to load is kind of loading some sort of JavaScript or isn't reachable

Try disabling JavaScript using this

from selenium.webdriver.Ie.options import Options

options = Options()
options.preferences.update({'javascript.enabled': False})
browser = webdriver.Ie(options=options,executable_path="path")

If it still doesn't work try removing all the capabilities.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sashank
  • 557
  • 6
  • 20
  • Im getting this error `AttributeError: 'Options' object has no attribute 'preferences'` from selenium.webdriver.Ie.options import Options, 'Ie' is not found, instead i replaced it with 'ie' which seems to be ok, but from options class preferences dosen't exist – Henry-G Jul 25 '20 at 10:36
  • Also, I tried chrome driver, it works perfectly so the problem is my internet explorer – Henry-G Jul 25 '20 at 10:36
  • I wish I could use chrome, I'm stuck with IE not even edge... I kinda have to make it work – Henry-G Jul 25 '20 at 10:39
  • hmm , I know you should be able to do it by changing the browser configuration to disable javascript by default – Sashank Jul 25 '20 at 10:40
  • Disabled it from tools, it seems to behave the same, something in the page is still not loading, on any page I try to load – Henry-G Jul 25 '20 at 10:44
1

If you look into the Required Configuration of Internet Explorer Driver the following points are clearly mentioned :

Protected Mode

On Internet Explorer 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings you have to choose "Internet Options" from the "Tools" menu and then click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled Enable Protected Mode.

ProtectedModeSettings

Further, @JimEvans in his article You're Doing It Wrong: IE Protected Mode and WebDriver clearly mentions :

Using the capability doesn't solve the underlying problem though. If a Protected Mode boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could result. To help warn people of this potential problem, the capability was given big scary-sounding names like INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS in Java and IntroduceInstabilityByIgnoringProtectedModeSettings in .NET. We really thought that telling the user that using this setting would introduce potential badness in their code would discourage its use, but it turned out not to be so.


Solution

You can access the url https://www.google.ro/?safe=active&ssui=on using the following solution:

from selenium import webdriver

driver = webdriver.Ie(executable_path=r'C:\WebDrivers\IEDriverServer.exe')
driver.get('https://www.google.ro/?safe=active&ssui=on')

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352