0

I'm trying to submit a form after entering the necessary fields on this website. So far it works if I don't change the tab to "NTETEXPRESS".

imports

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options
from selenium.common import exceptions as sel_excpt
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument("disable-popup-blocking")
options.add_experimental_option("detach",True)
chrome_driver_pth = ChromeDriverManager().install()
service = ChromeService(executable_path=chrome_driver_pth)

driver = webdriver.Chrome(service=service, options=options)

     

other_tab = False

url = r"https://www.texpresslanes.com/pricing/average-rates/"
segment_css = "#details-1-toll"
day = "#details-1-day"
time = "#details-1-time"
submit = "#wpcf7-f9-p10-o1 > form > div.form-row.last-row.grid-2 > div > div > input.wpcf7-form-control.wpcf7-submit.button-secondary"

if other_tab:
    net_tab= "#content > div.page-layout > div > div > article > div > div > div > div > section.module.module-traffic.module-pyt-tabs.full-width.simple-tabs.inserted > div > div > div.module-tabs > button.tab2"
    
    WebDriverWait(driver, 15).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, net_tab))
        )
        WebDriverWait(driver, 15).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, net_tab))
        ).click()




WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, segment_css)))
select_seg = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, segment_css)))

if not other_tab:
      select_seg.select_by_value("277")
else: 
      select_seg.select_by_value("283")
 
days = driver.find_element(By.CSS_SELECTOR, day_css)
time = driver.find_element(By.CSS_SELECTOR, time_css)

Select(days).select_by_value("monday")
Select(time).select_by_value("00:00:00")
# where it fails if other_tab = True
submit_bttn = driver.find_element(By.CSS_SELECTOR, submit)
submit_bttn.click()        

The failure message is either a timeout, or a Element is not interactable error for the form submission button.

Things that I've tried

  • More expected conditional waits / Waiting for the submit button to be clickable

  • Executing a script

driver.execute("arguments[0].click();",submit_bttn) 
# this works when other_tab = False

So I've actually went to the website, entered in all of the necessary fields, and called using the console (on chrome)

document.querySelector("#wpcf7-f9-p10-o1 > form > div.form-row.last-row.grid-2 > div > div > input.wpcf7-form-control.wpcf7-submit.button-secondary").click()

Again, this works with the first tab for the LBJ express, but not for the NTE35W tab. So I don't really know how to proceed.

  • Does this answer your question? [How do I switch to the active tab in Selenium?](https://stackoverflow.com/questions/28715942/how-do-i-switch-to-the-active-tab-in-selenium) – EvgenyKolyakov Jun 28 '22 at 19:29
  • I think that question refers to the browser tab, not that of a table/form within a website. – golden_curry2020 Jun 28 '22 at 19:36

1 Answers1

0

The submit buttons had the same css selector.

A workaround is to just find_elements and iterate through the list while handling any exception whenever a click is attempted.