版本为python3.9+selenium4.9.0,带完整代码,为两部分(图鉴的py文件[tujian.py],登录代码,[loginToB.py])
遇见的问题:
1、验证码获取不到元素(no such element)
原因:网页的验证码还没加载出来
解决方法:等2秒,等网页加载
time.sleep(2)
2、验证码位置问题(selenium.common.exception.ElementNotInteractableExpection:Message:element not interactable:[object HTMLButtonElement] has no size and location)
原因:新版的Selenium位置起始点从左上角变成了中心点
for xAndy in xAndyList:
x = int(xAndy.split(",")[0])
y = int(xAndy.split(",")[1])
# print("x=",x)
# print("y=",y)
act.move_to_element_with_offset(captchaDialog,x,y).click().perform()
解决办法:获取验证码元素的宽和高都除2,此时左上角坐标就是(-宽/2,-高/2),在用这个坐上角坐标