简体   繁体   English

无法通过Amazon EC2运行python selenium webdriver脚本

[英]Unable to run python selenium webdriver scripts over Amazon EC2

I am trying to run a python script in which I am opening a webpage and clicking on some element. 我试图运行一个python脚本,在该脚本中,我打开一个网页并单击某些元素。 But the script is running very slow and giving random exceptions . 但是该脚本运行非常缓慢,并给出了随机异常。

Mostly it halts at line driver = webdriver.Firefox() 通常,它在line driver = webdriver.Firefox()处停止

Message - 信息 -

selenium.common.exceptions.WebDriverException: Message: 'Can\\'t load the profile. selenium.common.exceptions.WebDriverException:消息:“无法加载配置文件。 Profile ?Dir: /tmp/tmp4liaEq Firefox output: Xlib: extension "RANDR" missing on display ":1733".\\n1403086712970\\taddons.xpi\\tDEBUG\\tstartup\\n1403086713204\\taddons.xpi\\tDEBUG\\tcheckForChanges\\n1403086713568\\taddons.xpi\\tDEBUG\\tNo changes found\\n' 配置文件?Dir:/ tmp / tmp4liaEq Firefox输出:Xlib:扩展名“ RANDR”在显示“:1733”上丢失。\\ n1403086712970 \\ taddons.xpi \\ tDEBUG \\ tstartup \\ n1403086713204 \\ taddons.xpi \\ tDEBUG \\ tcheckForChanges \\ n1403086713568 \\ taddons。 xpi \\ tDEBUG \\ t未找到更改\\ n'

Sometimes - driver.find_element_by_xpath("//a[@id='some_id']") Returning error that the element is not visible so can't be clicked. 有时driver.find_element_by_xpath("//a[@id='some_id']")返回错误,该元素不可见,因此无法单击。

The same script runs smoothly on my system that has 4GB RAM. 同一脚本在具有4GB RAM的系统上可以流畅运行。 (EC2 system specs ~ 600mb memory) (EC2系统规格〜600mb内存)

I tried looking into the system and "top" command returned - 我尝试调查系统,并返回“ top”命令-

604332k total, 577412k used, 26920k free, 6616k buffers

I have installed firefox and also xvfb since i am running the firefox headlessly 由于我无头运行Firefox,因此我已经安装了Firefox和xvfb

I was facing the same problem. 我面临着同样的问题。 Running the scripts as root solved the problem. 以root身份运行脚本解决了该问题。 Also making an user running the test a sudoer worked. 同时也使运行测试的用户更轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM