2017-07-26 119 views
2
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) 

该代码在Windows上运行10就好当我尝试在Windows 7上,网页加载运行,但我得到这个错误找上关闭的窗口元素的Python:“无法找到元素关闭窗口“ 我在网上寻找这个错误,这是关于Internet Explorer保护模式的东西。我试着添加“忽略保护模式设置”功能,但我得到了同样的错误。我能做什么?无法使用Selenium

回答

1

这里是回答你的问题:

当你与Selenium 3.4.0IEDriverServer 3.4.0工作与IE(v 10/11)错误:“无法找到对已关闭的窗口元素”可能由于发生几限制Internet ExplorerIEDriverServer.exe。为了避免这些错误,我们可以明确地通过DesiredCapabilities类设置nativeEventsrequireWindowFocustrue如下:

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".

您可以找到有关这个link这些事实更多的文档。

让我知道这个答案是否是您的问题。

+0

不幸的是,在我尝试了你所说的之后,出现了完全相同的错误。 – csmn123

+0

您的“缩放级别”设置为100%?硒,IEDriverServer和IE版本。谢谢 – DebanjanB

+0

是的,缩放级别设置为100%。 IE版本:11.0.9600.17843(IE 11)。硒版本:3.4.3。 IE webdriver版本:3.4.0.0 – csmn123