python - Selenium working with Chrome, but not headless Chrome -
i've developed couple python scripts using selenium and, @ first, phantomjs. while heading toward automated downloads, switched (headed) firefox (which worked) , chrome headless option won't have browser opening in front of me.
my first script, access page , couple html elements, works headless chrome.
the second one, however, works headed chrome. if add "headless" option, doesn't work anymore. when try print html in headless mode see why cannot find html element i'm looking for, have :
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>
with headed chrome, have complete html printed. how start headless chrome :
options = webdriver.chromeoptions() options.add_argument("--ignore-certificate-errors") options.add_argument("headless") driver = webdriver.chrome(chrome_options=options)
again, note works in of script. difference here need log in access page, then, why work head ? script made log in automatically anyway filling form.
python : 3.6.1, chrome : 60.0.3112.78 (64 bits), selenium : 3.4.3
any idea ? thanks.
edit : here beginning of code
url = 'https://10.11.227.21/tmui/' driver.get(url + "login.jsp") html_source = driver.page_source print(html_source) blocstatus = webdriverwait(driver, timeout).until(ec.presence_of_element_located((by.id, "username"))) inputelement = driver.find_element_by_id("username") inputelement.send_keys('actuallogin') inputelement = driver.find_element_by_id("passwd") inputelement.send_keys('actualpassword') inputelement.submit()
i had same experience you, , solved using xvfb , pyvirtualdisplay.
i use chromedrive=v2.3.1, chrome-browser=v60 , selenium=3.4.3
in headless chrome, of script seems not work expected.
please refer vpassapera's comment in https://gist.github.com/addyosmani/5336747.
how try below,
from pyvirtualdisplay import display display = display(visible=0, size=(800, 600)) display.start() # not use headless chrome option # options.add_argument('headless') url = 'https://10.11.227.21/tmui/' driver.get(url + "login.jsp") html_source = driver.page_source print(html_source) blocstatus = webdriverwait(driver, timeout).until(ec.presence_of_element_located((by.id, "username"))) inputelement = driver.find_element_by_id("username") inputelement.send_keys('actuallogin') inputelement = driver.find_element_by_id("passwd") inputelement.send_keys('actualpassword') inputelement.submit() display.stop()
xvfb required use "pyvortualdisplay"
$ sudo apt-get install -y xvfb
Comments
Post a Comment