Home > Software engineering >  Auto-checkin script for united airlines
Auto-checkin script for united airlines

Time:08-13

Trying to submit the check in form for United Airlines (https://www.united.com/en/us/checkin). I can't get the continue button to automate. The xpath is dynamic so is css selector. Can't find a name or id browser to find. How can I find this element? Never coded before so this is all I have been able to pickup from youtube

html for button

<button  type="submit">Continue</button>

Code so far:

from selenium import webdriver

browser = webdriver.Chrome('/Users/jeff/chromedriver/chromedriver')

browser.get('https://www.united.com/en/us/checkin')

browser.find_element('name', 'confirmationNumberModel.number').send_keys('AAAA1')

browser.find_element('name', 'confirmationNumberModel.lastName').send_keys('LastName')

browser.implicitly_wait(3)

CodePudding user response:

Try to locate button by XPath:

browser.find_element(By.XPATH, '//button[.="Continue"]').click()

You can also call submit method from any element inside form node:

browser.find_element('name', 'confirmationNumberModel.lastName').submit() 

P.S. Note that browser.implicitly_wait(3) should be called before locating elements

CodePudding user response:

Given the HTML:

<button  type="submit">Continue</button>

All the classnames are dynamically generated. So we can't use them and have to look out for the static element attributes.


Solution

To click on Continue you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "div[title='Confirmation or eTicket number'] button[type='submit']").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//button[@type='submit' and text()='Continue']").click()
    
  • Related