selenium模拟点击的几种方法探讨

every blog every motto: Although the world is full of suffering, it is full also of the overcoming of it

0. 前言

进行自动化测试时,常常需要点击元素,笔者在进行测试时,有时会遇到不可点击的问题,常常要在几种方法之间进行切换,遂进行小结,以备以后不时之需。

1. 正文

1.1 click

log.click()

注:
1. log搜索到的可点击的元素
2. 这种方法最常使用,但有时未能正确运行,笔者未进行深入研究,以后若有时间会进行相关测试。

1.2 动作链

brower.ActionChains(browser).move_to_elemnet(log).click(log).perform()

注:

  1. 笔者在进行测试程序时,
    会报错: selenium.common.exceptions.JavascriptException: Message: javascript error: Failed to execute ‘elementsFromPoint’ on ‘Document’: The provided double value is non-finite.
    (Session info: headless chrome=79.0.3945.117)
    于是选择第三种方法

1.3execute_script

browser.execute_script("arguments[0].click();",log)

参考文献

[1] https://blog.csdn.net/lly1122334/article/details/103492202

发布了39 篇原创文章 · 获赞 32 · 访问量 5792

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/104064027