Selenium exception analysis and solutions to common

introducing selenium given pycharm

Phenomenon: pycharm entered from selenium import webdriver, seleniummarked red

  • The reason 1: pycharm use of virtual environments is not installed selenium,
    Solution: By setting or terminal panel reinstall selenium in the pycharm
  • Reason 2: There are current projects selenium.py, and system package name conflicts cause,
    solution, rename the file

Driver and local service class anomaly

  1. Browser drive response is not found
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

or

WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

Reason: Find the corresponding browser can not drive
Workaround: Download the corresponding version of the browser chromedriver
or geckodriver geckodriver
under the current script into the Scripts folder or the path to the configuration environment variable, or into the Python directories (general under Python Scripts directory in the environment variable), or use the Browse option to specify the drive path options

  1. Not Found browser
WebDriverException: Message Can not connect to the Service chromedriver
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary

The reason: the Firefox browser was not found in the default path
Solution: Reinstall Firefox browser

  1. Drivers and browsers do not match
SessionNotCreatedException: Message: session not created: 
this version of ChromeDriver only supports Chrome version 76

The reason: the current version using chromedriver only supports Chrome76
Solution: Check the local version of the Chrome browser, download the corresponding chromedriver

  1. Driver blocked by the firewall
WebDriverException: Message: Can not connect to the Service IEDriverServer.exe

The reason: iedriverserver.exe blocked by the firewall
Solution: firewall settings to allow

  1. Not connect chromedriver Service
WebDriverException: Message: Can not connect ot the Service chromedriver

The reason: this script 127.0.0.1 ip access local chromedriver services, hosts not configured point to 127.0.0.1 localhost
Solution: Configure the local hosts, add: 127.0.0.1 localhost
6 RemoteDriverServerException: The remote server exception Solution: Make sure webdriver.Remote () in remote Webdriver service is OK

  1. ErrorInResponseException: Webdriver server response anomaly, the solution according to specific error information analysis

    Exception class not found: positioning / attribute acquiring / warning switch frame, Frame, window

  2. NoSuchElementException: No element solution: After waiting retry preceded sleep, or to put it another way targeting
  3. NoSuchAttributeException: This element has no attribute Solution: Make sure the elements are positioned to target elements, attributes check spelling
    3. NoAlertPresentException: not found alert pop-up box, the solution: To observe the page to see if a bomb box appears, with waiting or as sporadic element processing
  4. NoSuchFrameException: Not find the specified frame or iframe, Solution: Look id / name / index / positioning to the frame using the frame spelling or switch
  5. NoSuchWindowException: I did not find the window handle specified window Solution: Check the spelling of variable used window handle
  6. UnexpectedAlertPresentException: There have been bomb box without treatment, the solution: Switch to the warning box and handling, if sporadic, use try ... except deal with sporadic bomb box
  7. InvalidSwitchToTargetException: Switch to the specified window or frame error, the solution: view the window frame or whether the target
  8. UnexpectedTagNameException: Use Tag Name unlawful, Solution: Check spelling or use Selector CSS / xpath
    9. TimeoutException: find elements or a timeout operation, the solution, try again later

Operating element exception classes: Hide / inoperable state

  1. ElementNotVisibleException: Abnormal invisible element, Selenium can not directly operate the hidden element solution: add wait, using the normal step of display elements, or ancestor node js find the hidden attribute of the element (typically styple = "display: none") , and then removing the positioning operation attribute.
  2. StaleElementReferenceException: Stale element reference exception, used before to locate elements of a page refresh or after the jump, the solution: repositioning elements and operations
  3. InvalidElementStateException: Read-only element is abnormal element / non-clicks, etc., solution, or wait for removing elements js readonly / disable limit Once operating properties
  4. ElementNotSelectableException: The element can not be selected, Solution: Make sure to select whether the original label, whether disabled
  5. InvalidSelectorException: Positioning method that does not support or xpath syntax errors, does not return element Solution: Check whether the positioning elements used unpacking find_element using () method, the first parameter is the 'class name', 'link text' , 'particial link text' 'css selector', separate spaces non underscore, we are recommended to use By.CLASS_NAME way of using chrome develop a tool + Ctrl + F search to verify your writing xpath syntax.
  6. MoveTargetOutOfBoundsException: When using the move method ActionChains moved to a position unsuitable

Cookie access to relevant abnormalities

  1. InvalidCookieDomainException: Cookie appropriate domain name is invalid
  2. UnableToSetCookieException: Set Cookie abnormal

IME input method engine exception

  1. ImeNotAvailableException: The server does not support input method
  2. ImeActivationFailedException: Input abnormal activation

Guess you like

Origin www.cnblogs.com/superhin/p/11454861.html