平时我们在UI自动化时,尤其是一些管理员页面,APP的后台管理系统,经常会出现鼠标移入,才会展示一个list的情况。所以我们需要鼠标保持一入状态,然后才能去点击这种方法,一般都是比较难模拟的。接下来就给出下面面码,可以解决鼠标移入后才能进行点击的元素。
Alluser = driver.find_element_by_css_selector(titpath)
ActionChains(driver).move_to_element(Alluser).click_and_hold().perform() #鼠标移动到一级模块
driver.find_element_by_xpath(divpath).is_displayed() #展示二级模块隐藏的div
driver.find_element_by_css_selector(clickpath).click() #点击二级模块选项
############################################################################
为了反爬虫, 一些网站会记录你的鼠标动作, 因为爬虫通常不会产生鼠标动作. selenium也能控制鼠标的运动, 比如:
pwd_input = driver.find_element_by_css_selector('input.W_input[name=password]')
webdriver.ActionChains(driver).move_to_element(pwd_input).perform() #移动鼠标到我的密码输入框
网友评论