Selenium browser operation

1. Maximize the browser

After Webdriver opens the browser, it is not maximized by default. If you need to maximize the interface, you need to use the maximize_window() method to achieve it. The code is as follows:

from selenium import webdriver
driver=webdriver.Firefox()
driver.maximize_window()
# 将浏览器最大化

2. The height and width of the browser

In webdriver, in addition to maximizing the browser through the maximize_window() method, you can also customize the size of the interface.

from selenium import webdriver
driver=webdriver.Firefox()
driver.set_window_size(480,800)

3. Browser forward and backward

In the browser interface, you can manually click forward and backward to access the next page or return to the previous page. In selenium's webdriver, you can use the back() method to achieve back, and the forword() method to achieve forward. The code is as follows:

from selenium import webdriver
# 导入 webdriver
driver=webdriver.Firefox()
# 打开 firefox 浏览器
driver.get('http://www.chuangyijia.com/admin/login')
# 打开 LMD 后台登陆页面
driver.maximize_window()
# 窗口最大化
WebDriverWait(driver,10).until(expected_conditions.presence_o
f_element_located((By.ID,'email')))
# 显示等待,等待邮箱输入框
driver.find_element_by_id('email').send_keys('[email protected]')
# 输入用户名
driver.find_element_by_id('password').send_keys('12345678')
# 输入密码
driver.find_element_by_css_selector('button.btn').click()
# 点击登陆
driver.implicitly_wait(3)
# 隐式等待 3 秒
driver.find_element_by_css_selector('#dashboard-menu>li:nthchild(2)>a:nth-child(1)').click()
# 点击待审核创意
driver.find_element_by_css_selector('select.span1:nthchild(8)').click()
# 点击审核状态的下拉框
driver.back()
# 后退
driver.forword()
# 前进

4. Closing of the browser

At the end of a test, the browser that has been opened is often closed. By the way, here is a summary of the opening operation of the browser. The closing of the browser can be completed through the quit() method.

from selenium import webdriver
driver=webdriver.Firefox()
# 打开一个 firefox 浏览器
browser=webdriver.Ie()
# 打开 ie 浏览器
chrome=webdriver.Chrome()
# 打开 google 浏览器
driver.quit()

Guess you like

Origin blog.csdn.net/m0_65783113/article/details/130015824