python selenium鼠标点击操作

1、python selenium鼠标点击网页空白(google浏览器50.0.2661.102 有效,经验证firefox47.0.1该操作无效):
action = ActionChains (driver)
action.move_by_offset(0, 0).click ().perform (); #点击空白区域:坐标(0,0)
2、对于不可见的元素,driver不容易获取的元素,可用鼠标移动到元素所在位置进行点击输入操作:
e1 = driver.find_element_by_xpath (".//*[@id=‘passwor’]")
action = ActionChains (driver)
action.move_to_element (e1).click ().send_keys (“8b08c0bd2c536072a4bed2ddebcc4f01a73549106e04d12659aed56cf938d6b72f3a53149b488e4a309f2fe9851d8d3ad60a429cbe4e82dd16cfb1206dc7c7752ddf861a79374247777d76d3188061738b196fddd53e3f0ae1044c525fa9f35de6cfa0ce69dd2f2e30e4211acfd8a4d806d9c22bb5130aa68eceda6cc78c9630”).perform ()
3、对于不可见的元素,也可以动态调用js,改变属性为可见,再进行操作:
driver.find_element_by_id (‘login’).send_keys (‘12345678900’)
js = “document.getElementById(‘password’).style.display=‘block’” # 编写JS
driver.execute_script (js) # 执行JS
driver.find_element_by_id (‘password’).send_keys (‘123456’)
4、焦点滚动到指定位置
t1=driver.find_element_by_xpath(“html/body/div[4]/ul/li[1]/div/div/img”)#某元素的位置
driver.execute_script(“arguments[0].scrollIntoView();”, t1) #滚动到指定元素位置

猜你喜欢

转载自blog.csdn.net/fnms88/article/details/82863240