In web automation selenium python when running code without a headless working fine but with headless chrome it navigates to the unexpected page

0 votes

Using Python/selenium running without headless mode is working fine but with headless Chromedriver it navigates to an unexpected page.[expected dashboard but in headless navigates to profile after login but in normal working fine]
Note: in geckodriver headless working fine
Python code:

if value == "True":
    chromeOptions.add_argument("--headless")           
    chromeOptions.add_argument('window-size=1920,1080')         

capabilities = DesiredCapabilities.CHROME.copy()       
if self.getPlateform() == "Windows":
    chromedriver = self.SRC_DIR +'yxyz\\chromedriver.exe'
else:
    chromedriver = self.SRC_DIR +'yxyz/chromedriver'
    logging.info(chromedriver)
    return webdriver.Chrome(
        executable_path=chromedriver,
        options=chromeOptions,
        desired_capabilities = capability
    )
Jun 15, 2020 in Selenium by Raghvir
• 170 points
3,875 views
Hey @Raghvir, Are you getting any error in the process?
After login, I expected to user dashboard page but it navigates to the profile page. So the assertion fails.

Are you running it on a Linux or windows? As of today, when running chrome headless on Windows., you should include the  --disable-gpu flag

On both Linux and on the window as well.

Try something like this:

options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
options.add_argument('--disable-gpu')
options.add_argument('--headless')
chrome_driver_path = "C:\Python27\Scripts\chromedriver.exe" //your chromedriver path
nothing can change....thanks for looking into this hope we will find solution soon
Hey @Raghvir, did the above snippet help? Did you find a solution? Please post it as the answer in case you found a solution for the same.
Headless chrome may be faster on same machine than headed, try adding some wait and check if it works.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,150 points
15,720 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,484 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,028 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,143 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP