python #The description in the internet window cal

2019-02-21 04:50发布

问题:

import os
import time
import  random
import  webbrowser
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
binary = 'C:/Users/lee/Documents/IEDriverServer.exe'
browser = webdriver. Ie (binary)
browser.set_window_size(533,533)
browser.get('https://www.naver.com/')
time.sleep(10)
browser.quit()

回答1:

A couple of points :

  1. Keep the required imports only. Remove the unwanted imports to keep things simpler.
  2. Need to be careful with extra spaces as Python is sensitive to spaces and indents.
  3. To mention OS paths either use escaped back slashes (\\) or use single front slashes (/) along with the raw (r) switch.
  4. Here is your own working code with some minor tweaks:

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    import time
    
    cap = DesiredCapabilities().INTERNETEXPLORER
    cap['ignoreProtectedModeSettings'] = True
    browser = webdriver.Ie(capabilities=cap, executable_path="C:\\Utility\\BrowserDrivers\\IEDriverServer.exe")
    browser.get('https://www.naver.com/')
    browser.set_window_size(533,533)
    time.sleep(10)
    browser.quit()
    

Update

As you are seeing the error as WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode set, follow the steps below and execute your tests :

  • 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".
  • Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
  • The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
  • For Windows 10, you also need to set "Change the size of text, apps, and other items" to 100% in display settings.