Common WebDriver attributes:
# attribute Property description
1 driver.name Browser name
2 driver.current_url The current Url
3 driver.title Current page title
4 driver.page_source Current page source
5 driver.current_window_handle Handle to the window
6 driver.window_handles All handles to the current window
WebElement common methods:
# methods Methods described
1 driver.back() Browser Back
2 driver.forward() Browser forward
3 driver.refresh() Browser refresh
4 driver.close() Close current window
5 driver.quit() Exit the browser
6 driver.switch_to.frame() Switch to the frame
7 driver.switch_to.alert Switch to the alert
8 driver.switch_to.active_element() Switch to the active element
WebElement common attributes:
# attribute Property description
1 id logo
2 size Wide high
3 rect Width, height and coordinates
4 tag_name Tag name
5 text The text content
WebElement common methods:
# methods Methods described
1 send_keys() The input
2 clear() Empty content
3 click() Click on the
4 get_attribute() Get attribute values
5 is_selected() Selected or not
6 is_enabled() Whether the available
7 is_displayed() Whether or not shown
8 value_of_css_property() CSS attribute values
Code:
from selenium import webdriver from time import sleep from selenium.webdriver.remote.webelement import WebElement class TestCase1(object): def __init__(self): self.driver = webdriver.Chrome() self.driver.get('http://www.baidu.com') def test_prop(self): Print (self.driver.title) # print(self.driver.title) # Print (self.driver.window_handles) print(self.driver.current_window_handle Self.driver. Quit () def test_method(self): print(self.driver. Page_source) self.driver.find_element_by_id('kw').send_keys('GitHub') self.driver.find_element_by_id('su').click() sleep(2) Self.driver.back () # refresh(2) self.driver.forward() # refresh(2) Self.driver.close () # close the current TAB self.driver.quit() # exit the browser print('Pass') class TestCase2(object): def __init__(self): The self. The driver = webdriver. Chrome () # http://sahitest.com/demo/ URL to practice the Selenium self.driver.get('http://sahitest.com/demo/linkTest.htm') def test_webelement_prop(self): e = self.driver.find_element_by_id('t1') e1 = WebElement; Print (e) print(e) print(e) print(e) print(e test_webelement_method(self): E = self.driver.find_element_by_id('t1') e.send_keys('Hello world') # print(LLDB et_attribute('type')) # Print (LLDB et_attribute('name')) print(LLDB et_attribute('value')) e.clear( print(e.value_of_css_property('font')) print(e.value_of_css_property('color')) # self.driver.find_element_by_class_name('JSubmit('2'); return false; ').click() self.driver.quit() def test_method2(self): Form_element = self.driver.find_element_by_xpath('/ HTML /body/form[1]') # form_element.find_element_by_id('t1').send_keys('Hello world') sleep(2) self.driver.quit() if __name__ == '__main__': case1 = TestCase1() case2 = TestCase2() # case1.test_prop() # case1.test_method() # case2.test_webelement_method() case2.test_method2()Copy the code