环境:
编辑工具:
浏览器:
有问题可以联系qq:1776376537
# coding:utf-8
from common.base import Base
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
#打开火狐浏览器
driver = webdriver.Firefox()
#打开百度首页
driver.get("https://www.baidu.com")
baidu = Base(driver)
locall1 = ("link text","设置")
#鼠标移到到设置上,点击搜索设置
mouse = baidu.findElement(locall1)
ActionChains(driver).move_to_element(mouse).perform()
locall2 = ("link text","搜索设置")
baidu.click(locall2)
#每页显示50条
locall3 = ("xpath",".//*[@id='nr']/option[3]")
r1 = baidu.findElement(locall3).is_selected()
print(r1)#没有被选中打印flase
locall4 = ("id","nr")
select = baidu.findElement(locall4)
Select(select).select_by_index(2)
r2 = baidu.findElement(locall3).is_selected()
print(r2)#被选中打印True