2

I am running Python3,Django with selenium on Ubuntu.

I am trying to one a URL and login. This is my code:

 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')

However, when I run the program, I get below exception:

Exception Value:
Message: no such element (Session info: chrome=44.0.2403.157) (Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Linux 3.13.0-53-generic x86_64)

Above tells me that it is not able to locate the element id 'pass' that I am trying to find. But on Ubuntu box, i do not see any Chrome window pop up. It seems like it is doing this in background. How can make it launch a visible window so that I can troubleshoot?

=======

Update: Just noticed that when my framework opens a new chrome window, its owner is 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

This could probably the reason why I am not seeing the chrome window pop up. Any idea how to specify username that will open chrome window instance?

jincept
  • 279
  • 2
  • 5
  • 16

1 Answers1

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

should be

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

Basically, the opposite of instructions to run headless testing.

  • I tried it, but got "Message: unknown error: Chrome failed to start: exited abnormally". – jincept Aug 27 '15 at 20:17
  • @jincept Can you get a more verbose debugging message? It might help. http://stackoverflow.com/questions/22424737/message-uunknown-error-chrome-failed-to-start-exited-abnormally – NoSuchElephantException Aug 28 '15 at 03:10
  • Does it work if you use visible=True instead of 0/1? – NoSuchElephantException Aug 28 '15 at 03:14
  • I'm basing this off the documentation here: http://ponty.github.io/PyVirtualDisplay/usage.html --- BUT! This answer may actually be more relevant to the issue you're having now that you know how to change visible. http://stackoverflow.com/questions/27202131/firefox-started-by-selenium-ignores-the-display-created-by-pyvirtualdisplay – NoSuchElephantException Aug 28 '15 at 03:23