Search code examples
pythonseleniumheadless-browserpythonanywherepyvirtualdisplay

Selenium Pythonanywhere Cannot Locate Element


Anyone have any advice for locating elements on python anywhere using xvfb-run ? I get the driver up and display using the following code but when I try and locate an element by path I get cannot find element. This code works fine on my local machine. The driver does successfully navigate to lmcu.org when I print the url of the browser.

from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0,size=(800,600))
display.start()
browser = webdriver.Firefox()
browser.get("http://www.lmcu.org")
usr = browser.find_element_by_xpath(".//*[@id='LoginName']")

Solution

  • A useful debugging tool is to print the body text of the page you're looking at so you can verify that you're getting the page that you expect.