Current location - Recipe Complete Network - Complete cookbook - Selenium webdriver common properties and methods
Selenium webdriver common properties and methods

Attribute attribute description

driver.name? Browser name

driver.current_url? Current url

driver.title? Current page Title

driver.page_source current page source code

driver.current_window_handle? Window handle

driver.window_handles? All handles of the current window

Method ?Method description

driver.back() Browser back

driver.forward() Browser forward

driver.refresh() ?Browser refresh< /p>

driver.close() Close the current window

driver.quit() Exit the browser

driver.switch_to.frame() Switch to frame

driver.switch_to.alert() ? Switch to alert

driver.switch_to.active_element() ? Switch to active element

Source code:

from seleniumimport webdriver

from timeimport sleep

class Testcase(object):

def __init__(self):

self.driver = webdriver .Chrome()

self.driver.get('')

self.driver.maximize_window()

def test_prop(self):

print(self.driver.name)#Browser name

print(self.driver.current_url)#url

print(self.driver.title)#Web page title

print(self.driver.window_handles)#Handles

print(self.driver.page_source)#View source code

self.driver.quit( )

def test_method(self):

self.driver.find_element_by_id('kw').send_keys('selenium')

self.driver.find_element_by_id ('su').click()

sleep(2)

self.driver.back()#Back

sleep(2)

self.driver.refresh()#Refresh

sleep(2)

self.driver.forward()#Forward

self.driver .close()#Only close the current tab

self.driver.quit()#Close the browser

def test_windows(self):

self.driver .find_element_by_link_text('News').click()

windows =self.driver.window_handles

while 1:

for win windows:

self.driver.switch_to.window(w)

sleep(2)

if __name__ =='__main__':

case = Testcase( )

#case.test_prop()

#case.test_method()

case.test_windows()