Hi I am trying to run this very simple function using Selenium Webdriver which returns the title of a website.
from selenium import webdriver
from pyvirtualdisplay import Display
import traceback
browser = None
# displayDebug will open google.com and return the title
def displayDebug(o,d):
try:
display = Display(visible = 0, size = (800,600)).start()
browser = webdriver.Firefox()
browser.get('http://www.google.com')
myTitle = browser.title
except Exception as e:
myTitle = "Title not found"
traceback.print_exc()
finally:
if browser is not None:
browser.quit()
display.stop()
return myTitle
The result of this function is an empty string. If I define myTitle above the browser.get statement (as some random string), myTitle is defined as the random string. I am not sure if browser.title is returning an empty string, or if the try statement is terminated (though I suspect the former, because otherwise, myTitle would be "Title not found"). This leads me to believe this is an issue with the headless display.
I looked through many of the forum posts on this topic. For reference, I am using a version of Selenium older than version 3. I installed xvfbwrapper. I did not install the pythonanywhere-compatible firefox version on my local machine, am I supposed to? Any suggestions would be appreciated.
Thank you