1

I am new to using Selenium on Python for webscraping and am having issues navigating through a webpage. My current code navigates through the webpage by clicking buttons using:

web.find_element("xpath", '').click()

with the appropriate xpath in the single parentheses.

I am attempting to "click" a button whose HTML looks like that:

<a id="medicalUsageNext" href="#myPereferences" data-slide="next" class="btn btn-primary pull-right margin10-b gtm_medical_service_next" title="Next" role="button">

 Next
 <i class="icon-caret-right"></i>
 </a> 

Despite various ways of attempting to click this button (adding an implicit wait, selecting by css, text, or type), I continue to get the ElementNotInteractableException.

Here is one (of many) ways I've attempted to click the button:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

web = webdriver.Chrome()
web.implicitly_wait(10)
web.get('https://apply.coveredca.com/lw-shopandcompare/?lang=en_EN')

zip2 = "90210"
income2 = "100000"
year_1 = "2022" 
household_1 = "1"
subsidy_household_size = "2"

web.find_element("xpath", '//*[@id="screeningquestions-zip"]').send_keys(zip2)
web.find_element("xpath", '//*[@id="screeningquestions- 
householdincomeperyear"]').send_keys(income2)

year = web.find_element("xpath", '//*[@id="screeningquestions-enrollyear"]')
year.send_keys(year_1)
year.send_keys(Keys.RETURN)

hh = web.find_element("xpath", '//*[@id="screeningquestions-howmanypeopleinhousehold"]')
hh.send_keys(subsidy_household_size)
hh.send_keys(Keys.RETURN)

for x1 in range(0, int(household_1)):
    temp1 = str(x1)
    web.find_element("xpath", '//*[@id="screeningquestions-age-'+temp1+'"]').send_keys("33")

for x2 in range(int(household_1), int(subsidy_household_size)):
    temp2 = str(x2)
    web.find_element("xpath", '//*[@id="screeningquestions-age-'+temp2+'"]').send_keys("35")
    temp3 = str(x2+1)
    web.find_element("xpath", '//*[@id="app-container"]/main/div/div/div[2]/div/div/div/form/span[3]/div['+temp3+']/div[3]/div[1]/label/span[1]').click()

web.find_element("xpath", '//*[@id="account-creation-access-code-invalid-modal-button"]').click()
web.find_element("xpath", '/html/body/div[3]/div/div/div/div[2]/div/div[1]/button').click()

web.find_element("xpath", '//*[@id="shopandcompare-previewplans"]').click()
web.find_element("xpath", '//*[@id="providerSearchNext"]').click()
web.find_element("xpath", '//*[@id="medicalUsageNext"]').click

For reference, this clicks through the following website: https://apply.coveredca.com/lw-shopandcompare/?lang=en_EN

I've been working to fix this for a few days and really appreciate any help.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Zac Hall
  • 11
  • 2

1 Answers1

1

To click on the element with text as Next you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Next"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#medicalUsageNext[data-slide='next'][title='Next']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='medicalUsageNext' and @data-slide='next'][@title='Next']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you so much., undetected selenium, this was giving me problems for a few days. For future reference, what is it that makes this button different from previous ones; and what makes it require these different functions as compared to previous operations? – Zac Hall Jul 20 '22 at 03:18