关于webdriver的click()事件无返回值无报错的问题

from selenium import webdriver
import requests
import time

url = 'http://admin.tudoubb.cn/admin_tigjy9v3uqa0o5efs.php/cloudbill/agents/user?ref=addtabs'

def login():
    driver = webdriver.Safari()
    driver.get(url=url)

    '''使用js'''
    # js = 'document.querySelector("#thirdpart-login > div.login-area.password-div > a")'
    # driver.execute_script(js)

    '''使用xpath匹配'''
    driver.find_element_by_xpath('//*[@id="thirdpart-login"]/div[2]').click()
    time.sleep(1)

    driver.find_element_by_xpath('//*[@id="pd-form-username"]').send_keys('***********')
    driver.find_element_by_xpath('//*[@id="pd-form-password"]').send_keys('***********')
    driver.find_element_by_xpath('//*[@id="login-form"]/div[5]/button').click()
    time.sleep(2)
    driver.quit()

login()

Traceback (most recent call last):
File “/Users/scrooge/PycharmProjects/pythonProject/test.py”, line 25, in
login()
File “/Users/scrooge/PycharmProjects/pythonProject/test.py”, line 20, in login
driver.find_element_by_xpath(‘//*[@id=”pd-form-password”]’).send_keys(‘**‘)
File “/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py”, line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File “/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webelement.py”, line 633, in _execute
return self._parent.execute(command, params)
File “/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py”, line 321, in execute
self.error_handler.check_response(response)
File “/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py”, line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: The target element is not interactable and could not be clicked
进程已结束,退出代码1

执行代码第一个click()事件没有反应也没有报错,然后直接执行了第一个sned_keys()。

请求指点一下这个问题的发生原因和解决方法。

最佳答案

并且selenium ide 录制的点击元素就是.password-div

1个月前 评论
SilenceHL 1个月前
讨论数量: 2

' driver.find_element_by_css_selector('.password-div').click() ' 使用css的class属性定位出现以下报错:

selenium.common.exceptions.ElementNotInteractableException: Message: The target element is not interactable and could not be clicked

1个月前 评论

并且selenium ide 录制的点击元素就是.password-div

1个月前 评论
SilenceHL 1个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!