2017-07-26 56 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