Package: selenium
IntroductionPython language bindings for Selenium WebDriver.Theseleniumpackage is used to automate web browser interaction from Python.Home:https://selenium.devGitHub:https://github.com/SeleniumHQ/SeleniumPyPI:https://pypi.org/project/selenium/IRC/Slack:Selenium chat roomSeveral browsers/drivers are supported (Firefox, Chrome, Internet Explorer), as well as the Remote protocol.Supported Python VersionsPython 3.8+InstallingIf you havepipon your system, you can simply install or upgrade the Python bindings:pip install -U seleniumAlternately, you can download the source distribution fromPyPI <https://pypi.org/project/selenium/#files>, unarchive it, and run:python setup.py installNote: You may want to consider usingvirtualenvto create isolated Python environments.DriversSelenium requires a driver to interface with the chosen browser. Firefox,
for example, requiresgeckodriver, which needs to be installed before the below examples can be run. Make sure it’s in yourPATH, e. g., place it in/usr/binor/usr/local/bin.Failure to observe this step will give you an errorselenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.Other supported browsers will have their own drivers available. Links to some of the more popular browser drivers follow.Chrome:https://chromedriver.chromium.org/downloadsEdge:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/Firefox:https://github.com/mozilla/geckodriver/releasesSafari:https://webkit.org/blog/6900/webdriver-support-in-safari-10/Example 0:open a new Firefox browserload the page at the given URLfromseleniumimportwebdriverbrowser=webdriver.Firefox()browser.get('http://selenium.dev/')Example 1:open a new Firefox browserload the Yahoo homepagesearch for “seleniumhq”close the browserfromseleniumimportwebdriverfromselenium.webdriver.common.byimportByfromselenium.webdriver.common.keysimportKeysbrowser=webdriver.Firefox()browser.get('http://www.yahoo.com')assert'Yahoo'inbrowser.titleelem=browser.find_element(By.NAME,'p')# Find the search boxelem.send_keys('seleniumhq'+Keys.RETURN)browser.quit()Example 2:Selenium WebDriver is often used as a basis for testing web applications.  Here is a simple example using Python’s standardunittestlibrary:importunittestfromseleniumimportwebdriverclassGoogleTestCase(unittest.TestCase):defsetUp(self):self.browser=webdriver.Firefox()self.addCleanup(self.browser.quit)deftest_page_title(self):self.browser.get('http://www.google.com')self.assertIn('Google',self.browser.title)if__name__=='__main__':unittest.main(verbosity=2)Selenium Grid (optional)For local Selenium scripts, the Java server is not needed.To use Selenium remotely, you need to also run the Selenium grid.
For information on running Selenium Grid:https://www.selenium.dev/documentation/grid/getting_started/To use Remote WebDriver see:https://www.selenium.dev/documentation/webdriver/drivers/remote_webdriver/?tab=pythonUse The Source Luke!View source code online:Official:https://github.com/SeleniumHQ/selenium/tree/trunk/pyContributingCreate a branch for your workEnsuretoxis installed (using avirtualenvis recommended)python3.8 -m venv .venv && . .venv/bin/activate && pip install toxAfter making changes, before committing executetox -e lintingIf tox exits0, commit and push otherwise fix the newly introduced breakages.flake8requires manual fixesblackwill often rewrite the breakages automatically, however the files are unstaged and should staged again.isortwill often rewrite the breakages automatically, however the files are unstaged and should staged again.