1

I tried automating the below code with headful mode and it works but not in headless mode. Throws a lot of javascript errors and finally says unable to find the element.

chrome_options = Options()
chrome_options.headless = True
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
chrome_options.add_argument(
    "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('chromedriver.exe',options=chrome_options)
driver.get('https://www.southwest.com/air/low-fare-calendar/select-dates.html?adultPassengersCount=1&currencyCode=USD&departureDate=2021-02-01&destinationAirportCode=MCO&originationAirportCode=ALB&passengerType=ADULT&returnAirportCode=&returnDate=&tripType=oneway')
time.sleep(2)
driver.find_element_by_xpath('//div[@class="flyout-trigger list-box"]').click()
time.sleep(1)
driver.find_element_by_id("Listbox_10--item-3").click()
time.sleep(1)
driver.save_screenshot("screenshot_after.png")
driver.quit()
3
  • Try adding window size in options this sometimes happens with setting it to headless. Commented Jan 27, 2021 at 22:57
  • @ArundeepChohan - it didnt work. this is my python code. chrome_options.add_argument("--window-size=1920,1080") Commented Jan 27, 2021 at 23:05
  • It seems to determine that it's a bot from what I can tell when it opens in the normal view. Commented Jan 27, 2021 at 23:33

1 Answer 1

2

When I went to the driver.get() it had some errors I am not 100% sure if it's bot detection which when I disabled navigator.webdriver it seemed to function correctly.

chrome_options.add_argument('--disable-blink-features=AutomationControlled')
Sign up to request clarification or add additional context in comments.

1 Comment

developer.mozilla.org/en-US/docs/Web/API/Navigator/webdriver if anyone is looking into this , its enabled by default in headless mode

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.