From selenium import webdriverfrom selenium.webdriver.common.keys import keysdriver = Webdriver. Firefox () driver.get ("http://www.python.org") assert "Python" in Driver.titleelem = Driver.find_element_by_name ("q") Elem.clear () Elem.send_keys ("Pycon") Elem.send_keys (Keys.return) assert "No results found." Not in driver.page_source# Driver.close () exit a sub-page
Driver.quit () Exit browser
A simple little chestnut.
One of the interesting input methods
For i In "SDSFA": elem.send_keys ("Pycon")
Import unittestfrom Selenium import webdriverfrom selenium.webdriver.common.keys import Keysclass pythonorgsearch ( UnitTest. TestCase): def setUp (self): self.driver = Webdriver. Firefox () def test_search_in_python_org (self): driver = self.driver driver.get ("http://www.python.org ") Self.assertin (" Python ", driver.title) elem = Driver.find_element_by_name (" q ") Elem.send_keys (" Pycon ") Elem.send_keys (Keys.return) assert" No results found. "Not in Driver.page_source def tearDown ( Self): self.driver.quit () if __name__ = = "__main__": Unittest.main ()
Refer to the official documentation from Http://selenium-python.readthedocs.io/getting-started.html.
Selenium Webdriver Interface