[英]Issue when running Python script with Selenium over GCP Cloud Run
I have this python script in which I need to login and retrieve an access_token from an authentication server, the process is as follows, navigate to the authentication server with a given URL, embed given username and password in corresponding fields, click 'login', access_token should be in the refreshed URL, so wait for 5 seconds and then retrieve the updated URL, slice it and get the access_token.我有这个 python 脚本,我需要在其中登录并从身份验证服务器检索 access_token,过程如下,使用给定的 URL 导航到身份验证服务器,在相应字段中嵌入给定的用户名和密码,单击“登录”, access_token应该在刷新后的URL中,所以等待5秒再取出更新后的URL,切片得到access_token。
On my local machine I was able to retrieve the Token and successfully complete the script.在我的本地机器上,我能够检索令牌并成功完成脚本。
However I want to deploy this script to Cloud Run, so I created the DockerFile and the python dependencies "requirment.txt" which I believe are accurate.但是,我想将此脚本部署到 Cloud Run,因此我创建了 DockerFile 和 python 依赖项“requirment.txt”,我认为这是准确的。
After the whole thing is deployed and, I try to run the service from Cloud Scheduler as usual, I get this error整个部署完成后,我尝试像往常一样从 Cloud Scheduler 运行服务,但出现此错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="email"]"}
Python code from my local machine, working perfectly我本地机器上的 Python 代码,完美运行
Update: The next day I found that the issue came back, and the run failed:/ same error更新:第二天发现问题又来了,运行失败:/同样的错误
The success of the day before前一天的成功
I figured it out, apparently, the implicit wait I had wouldn't be caught on GCP, would work on my local however, which is weird, I needed to implement an explicit - one line such as this.我想通了,显然,我的隐式等待不会在 GCP 上被捕获,但会在我的本地工作,这很奇怪,我需要实现一个显式的 - 一行这样的。
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
WebDriverWait(browser, 50).until(EC.presence_of_element_located((By.ID, "app")))
Basically what it did is wait till the page is refreshed and an element from the next page is returned to give the URL variable to the slicing part of my code.基本上它所做的就是等到刷新页面并返回下一页中的元素以将 URL 变量提供给我的代码的切片部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.