python-selenium-chromedriver 没有启动任何可见窗口

标签 python ubuntu selenium selenium-chromedriver

我在 Ubuntu 上运行 Python3、Django 和 selenium。

我正在尝试一个 URL 并登录。这是我的代码:

 from selenium import webdriver
 from selenium.webdriver.common.proxy import *
 import os
 from selenium.webdriver.common.keys import Keys
 from selenium.webdriver.support.ui import Select
 from selenium.webdriver.chrome.options import Options
 from pyvirtualdisplay import Display

  display = Display(visible=0, size=(800, 600))
  display.start()

  chromedriver = "/tmp/chromedriver"
  os.environ["webdriver.chrome.driver"] = chromedriver

  service_log_path = "/tmp/chromedriver.log"
  service_args = ['--verbose']
  driver = webdriver.Chrome(chromedriver,service_args=service_args,service_log_path=service_log_path)
  driver.get(url)
  driver.implicitly_wait(5)
  password = driver.find_element_by_name('pass')

但是,当我运行程序时,出现以下异常:

异常值:
消息:没有这样的元素
( session 信息:chrome=44.0.2403.157)
(驱动程序信息:chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),平台=Linux 3.13.0-53-generic x86_64)


上面告诉我它无法找到我试图找到的元素 id 'pass'。但是在 Ubuntu 盒子上,我没有看到任何 Chrome 窗口弹出。似乎它正在后台执行此操作。如何让它启动一个可见窗口以便我进行故障排除?

=======

更新:
刚刚注意到,当我的框架打开一个新的 chrome 窗口时,它的所有者是 apache (www-data)。
root@ubuntu:# ps -ax | grep chrome             
 5729 ?        Sl     0:00 /opt/google/chrome/chrome --type=renderer --enable-logging --log-level=0 --test-type=webdriver --enable-deferred-image-decoding --lang=en-US --user-data-dir=/tmp/.com.google.Chrome.jrPfBd --v8-natives-passed-by-fd --v8-snapshot-passed-by-fd --extension-process --enable-webrtc-hw-h264-encoding --disable-client-side-phishing-detection --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-pinch-virtual-viewport --enable-delegated-renderer --num-raster-threads=2 --gpu-rasterization-msaa-sample-count=8 --use-image-texture-target=3553 --disable-accelerated-video-decode --disable-webrtc-hw-encoding --disable-gpu-compositing --channel=5640.2.1387090022

root@ubuntu:# ls -ld /proc/5729
dr-xr-xr-x 9 www-data www-data 0 Aug 24 12:09 /proc/5729

这可能是我没有看到 chrome 窗口弹出的原因。知道如何指定将打开 chrome 窗口实例的用户名吗?

最佳答案

display = Display(visible=0, size=(800, 600))

应该
display = Display(visible=1, size=(800, 600))

基本上,the opposite of instructions to run headless testing .

关于python-selenium-chromedriver 没有启动任何可见窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32189237/

相关文章:

Python Selenium 无法在 Frameset > Frame 中找到元素

python - 两个不同时区的 `time` 对象的比较

python - 混用python和bash shell的xargs命令疑惑

linux - 使用 Getopts 传递多个强制标志的问题

security - 如何使用 iptable 阻止来自外部网络的网络流量?

selenium - 如何使用selenium webdriver处理ModalDialog?

Selenium CSS 定位器用于嵌套 div 内的跨度文本

python - 检查以确保字符串不包含多个值

python - 获取应用程序错误 : 2 in GAE PyDev application when deployed on app engine. 在本地工作正常

python - 列出软件包/模块以及它们安装在哪个 Python 发行版中,Ubuntu