selenium3 + python summarize the basic operation of the automation 6- (a)

I. Introduction

Affected by the epidemic, he has been at home unemployed, unable to work. Use of free time according to their attention a park owner's blog to learn about automation knowledge, some of the content review untimely really easy to forget. The summary of the main contents include: simple operation, keyboard, mouse, select the drop-down box.

Second, the content outline

Third, the practical application

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
driver.implicitly_wait(10)

"""
#1 模拟键盘-百度搜索
driver.find_element_by_id("kw").send_keys("python")
sleep(2)
driver.find_element_by_id("kw").submit()#submit()模拟enter建提交表单
# driver.find_element_by_id("su").click()#鼠标点击“百度一下”
#driver.find_element_by_id("kw").send_keys(Keys.ENTER)#模拟enter键操作回车按钮

#2 复习xpath模糊定位
driver.find_element_by_xpath('//*[contains(text(),"hao123")]').click()"""

#3 鼠标操作-百度设置按钮
from selenium.webdriver.common.action_chains import ActionChains
shezhi=driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(shezhi).perform()
sleep(1)
driver.find_element_by_xpath('//*[@class="bdpfmenu"]/a[1]').click()#点击搜索设置
sleep(1)

#4 select下拉框-设置页中页码显示设置(接3代码)
#4.1二次定位:先定位下拉框,再定位选项
# s=driver.find_element_by_id('nr')
# s.find_element_by_xpath('//option[@value="20"]').click()
# 4.2直接定位选项
# driver.find_element_by_xpath('//*[@id="nr"]/option[3]').click()
#4.3 select模块
from selenium.webdriver.support.select import Select
s=driver.find_element_by_id("nr")
Select(s).select_by_index(1)
sleep(1)
Select(s).select_by_value("50")
sleep(1)
Select(s).select_by_visible_text("每页显示20条")
sleep(1)
driver.find_element_by_link_text("保存设置").click()
sleep(1)
driver.quit()

 参考内容来自于:https://www.cnblogs.com/yoyoketang/        

Guess you like

Origin www.cnblogs.com/xiaobeibi/p/12307213.html