Reputation: 268
def check_text(browser, sitename):
browser.get(sitename)
try:
text = browser.find_element_by_class_name("text_content").text
if "foo" in text:
print("ok")
else:
print("not ok")
except NoSuchElementException:
print("no such elem")
def check_internet_explorer():
sitename="*foo site*"
caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
ie = webdriver.Ie(capabilities=caps)
check_text(ie, sitename)
This code works just fine on windows 10. When I try to run it on windows 7, the webpage loads but I get this error: "Unable to find element on closed window" I looked for this error online and it's something about internet explorer protected mode. I tried adding the "ignore protect mode settings" capability, but I get the same error. What can I do?
Upvotes: 2
Views: 1349
Reputation: 193348
Here is the Answer to your Question:
When you work with Selenium 3.4.0
, IEDriverServer 3.4.0
with IE(v 10/11)
the error: "Unable to find element on closed window" may occur due to several limitations of Internet Explorer
and the IEDriverServer.exe
. To prevent those errors we can explicitly set the nativeEvents
and requireWindowFocus
to true
through the DesiredCapabilities
class as follows:
caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
caps['nativeEvents'] = True
caps['ignoreZoomSetting'] = True
caps['requireWindowFocus'] = True
caps['InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
ie = webdriver.Ie(capabilities=caps)
As you are facing issue on
Windows 7
the documentation mentions the following points: On IE 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, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
You can find more documentation about these facts in this link.
Let me know if this Answers your Question.
Upvotes: 1