Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium将等待用户单击按钮_Python_Selenium - Fatal编程技术网

Python Selenium将等待用户单击按钮

Python Selenium将等待用户单击按钮,python,selenium,Python,Selenium,我必须让用户提供OTP并点击按钮的网站实现自动化。由于OTP未知,此部分无法自动化。因此,我需要selenium脚本等待用户单击按钮。 有什么方法可以做到这一点吗?(通过selenium而不是用户交互) 我试过这个: from selenium.webdriver.support.ui import WebDriverWait WebDriverWait(driver, 1).until(lambda d: d.execute_script("return document.getEl

我必须让用户提供OTP并点击按钮的网站实现自动化。由于OTP未知,此部分无法自动化。因此,我需要selenium脚本等待用户单击按钮。 有什么方法可以做到这一点吗?(通过selenium而不是用户交互)

我试过这个:

from selenium.webdriver.support.ui import WebDriverWait
WebDriverWait(driver, 1).until(lambda d: d.execute_script("return document.getElementById('loginbutton').clicked")=="true")
但会引发以下错误:

WebDriverWait(驱动程序,1).until(lambda d:d.execute_脚本(“return document.getElementById('loginbutton')。clicked”)=“true”) 文件“C:\Users\project\venv\lib\site packages\selenium\webdriver\support\wait.py”,第80行,直到 引发TimeoutException(消息、屏幕、堆栈跟踪) selenium.common.Exception.TimeoutException:消息: 流程结束,退出代码为1

document.getElementById('loginbutton').clicked
在开发人员工具上执行时给出未定义的,这可能是上述错误的原因吗?

这是一种“黑客”方法,但您可以检查URL,直到它更改以确认成功登录

例如,在尝试登录时,您的url可能如下所示:
https://www.yoururl.com/login

现在获取成功登录的url:

https://www.yoururl.com/dashboard

现在您可以编写一个循环来获取当前URL并进行检查,下面我将列出两个可以使用的示例。您需要修改它以适合您的具体情况

您可以使用
.current\u url
方法来帮助您完成此操作

while browser.current_url == 'https://www.yoururl.com/login':
    # still at the login page
    pass

print("Successful sign in!")


.clicked不是dom元素的方法或属性。我是从以下内容获得的:如何检查按钮是否被单击?如果需要手动执行,我建议使用提示通知用户执行他们必须执行的操作,然后单击“完成”。您可以在提示符关闭后恢复Selenium调用。仅仅使用Selenium没有其他方法吗?
while browser.current_url != 'https://www.yoururl.com/dashboard':
    # still at the login page
    pass

print("Successful sign in!")