python selenium 点击_Python使用selenium模拟点击(二)

本篇文章是接着第一篇文章讲的

要实现功能》搜索完毕,自动点击

1146047-20190305171019406-899006712.gif

这个功能做的停操蛋的,(忍不住想骂人)

按照我的做好,F12看看第一个a标签class 或者id,然后使用

find_element_by_id找到,点击就可以了

可是,他没有id,没有class 也没有name

没办法了,假如遇到这种情况,

find_element_by_xpath 使用这个

然后

("div[@id='1']/h3/a").click()

卧槽,他报错,说找不到指定的位置~~这很尴尬,然后又重新弄

看文档找到了一个 get_attribute 获取方法

结果也没用~~死活报错~~死活找不到

后面又找到一个办法

先引用from selenium.webdriver.common.action_chains import

ActionChains(seleniumGoo).move_by_offset(x,y).click().perform()

鼠标左键点击

ActionChains(seleniumGoo).move_by_offset(x, y).context_click().perform() # 鼠标右键点击

我去

,我就用这个办法做出来的

ActionChains(seleniumGoo).move_by_offset(-480, 126).click().perform() # 鼠标左键点击x坐标,y坐标

demo:

#coding:utf8

from selenium importwebdriverimporttimefrom selenium.webdriver.common.action_chains importActionChainsdefMian():

seleniumGoo=webdriver.Chrome()

seleniumGoo.get("https:www.baidu.com")

seleniumGoo.find_element_by_xpath()#seleniumGoo.find_element_by_id("kw")

seleniumGoo.find_element_by_id("kw").send_keys("Cgrain博客园")

seleniumGoo.find_element_by_id('su').click()

time.sleep(2)

ActionChains(seleniumGoo).move_by_offset(-480, 126).click().perform() #鼠标左键点击, 200为x坐标, 100为y坐标

#time.sleep(2)

#("div[@id='1']/h3/a").click()

#ActionChains(seleniumGoo).move_by_offset(-480, 126).context_click().perform() # 鼠标右键点击

time.sleep(20)if __name__ == "__main__":

Mian()

End,脱坑,觉得好的话点个关注+赞哦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值