One of Selenium+python learning

Source: Internet
Author: User

Just getting Started Selenium+python, after the successful experiment, record the process.

The first is to know the above to see a selenium+python on the example, so he tried to build the environment to start the experiment.

Follow the author's code after the execution, unexpectedly error ~

The code is as follows:

# coding=utf-8from Selenium Import webdriverbrowser = Webdriver. Firefox () browser.get ("http://zhihu.com") Browser.close ()

Then run, unexpectedly error.

In fact, the above code is not a problem, but, I would like to use the API to familiarize yourself with webdriver, so on the Webdriver API view: http://selenium-python.readthedocs.io/api.html

Follow the API example to write code like this:

#Coding=utf-8 fromSelenium.webdriverImportFirefox fromSelenium.webdriver.support.eventsImportEventfiringwebdriver, AbstracteventlistenerclassMyListener (abstracteventlistener):defbefore_navigate_to (self, URL, driver):Print("before navigate to%s"%URL)defafter_navigate_to (self, URL, driver):Print("After navigate to%s"%URL) driver=Firefox () ef_driver=Eventfiringwebdriver (Driver,mylistener ()) Ef_driver.get ("http://zhihu.com")assert "Testart" inchef_driver.titleef_driver.close ()

After execution, the error is as follows: selenium.common.exceptions.WebDriverException:Message: ' geckodriver ' executable needs to is in PATH.

Find an article that has resolved the problem: http://www.cnblogs.com/yousuosiyss/p/6882420.html

Select one of the ways to "download Geckodriver.exe" and follow these steps:

1.:https://github.com/mozilla/geckodriver/releases, according to their own computer, download the Win64 bit;
2. In the Firefox installation directory, unzip the Geckodriver, and then add the path to PATH environment variable, do not report this error;
3. However, a new error was reported "Selenium.common.exceptions.WebDriverException:Message:Unable to find a matching set of capabilities";
4. Continue online check, because I downloaded the geckodriver is V0.16.1 version, this version and selenium3.4.2 incompatible, need to use deckdriverV0.15 version;
5. Re-download the version of deckodriverV0.15, OK, do not report this mistake, but, also reported a new fault "Selenium.common.exceptions.WebDriverException:Message: Unsupported Marionette Protocol version 2, required 3;
6. Continue to check the reason, said the Firefox version is too low, need to upgrade to the latest version, OK, update Firefox, problem solving.

In fact, according to the author's share, will soon be able to solve the problem, but I follow the author's normal operation down, still reported the first mistake, a variety of attempts have not been done, and then on the Internet to search for the experience of others to share, finally solved the problem.
The following is an attempt to supplement the results:
Step 2 is to add the installation directory of Firefox to the PATH environment variable, after adding the completion, if still reported the same error, restart CMD and IDE, generally normal, if there are errors described by the author, you can continue to follow the author's above steps.

The above is a small experience, record.

One of Selenium+python learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.