AWS EC2 Ubuntu无头硒send_key不起作用
我用硒(Python)编写了一个小机器人,该机器人在我的笔记本电脑(Ubuntu)中完美工作,无论是无头还是GUI。尽管如此,当我尝试使用Ubuntu在AWS EC2计算机中执行相同的代码时,代码不起作用。当我使用函数发送send_keys然后显示文本时,它仍然是
driver.find_element_by_name('email').send_keys('[email protected]')
driver.find_element_by_name('email').text
我在服务器中使用的选项为:
options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=1920,1080")
options.add_argument("--disable-gpu")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
我在笔记本电脑中使用完全相同的代码,并且可以使用,相同的软件包等
I wrote a small bot using selenium (python) that is working perfectly in my laptop (ubuntu), both headless and with GUI. Nonetheless, when I try to execute the same code in an AWS EC2 machine with Ubuntu the code does not work. When I use the function to send_keys and then display the text, it is still empty
driver.find_element_by_name('email').send_keys('[email protected]')
driver.find_element_by_name('email').text
the options that I am using in the server are:
options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=1920,1080")
options.add_argument("--disable-gpu")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
I use the exact same code in my laptop and it works, same packages, etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许只需要明确的等待?
或者您甚至也可以尝试JS:
进口:
Maybe it just requires explicit wait?
or You can even try with JS as well:
Imports: