'Fix wait time for Selenium Form using Python

I'm new to Python and am trying to automate a form fill up. I have done all the work but when trying to "Submit" it's not reading the XPATH and hence not clicking.

HTML:

<input style="text-align: center; height: 24px;" onclick="return (Button.OnClick(this, event));" onfocus="return (Button.OnFocus(this, event));" id="FormControl_V1_I1_B12" scriptclass="Button" class="t_cP1RLqWVMhs644yI_0 bg_cP1RLqWVMhs644yI_0 a4_cP1RLqWVMhs644yI_0" wrapped="true" direction="ltr" viewdatanode="13" formid="FormControl" originalid="V1_I1_B12" tabindex="0" title="" buttonid="CTRL10_5" value="Submit" type="button">

Here is the Python Code (the 2nd code handles the Ok popup):

click_value = web.find_element(By.XPATH('//*[@id="FormControl_V1_I1_B12"]')).get_attribute("onclick")
print(click_value)

web.switch_to.alert.accept()

Element snapshot:

enter image description here

Here is the HTML tag:

enter image description here



Solution 1:[1]

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

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#FormControl_V1_I1_B12[formid='FormControl'][value='Submit']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='FormControl_V1_I1_B12' and @formid='FormControl'][@value='Submit']"))).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
    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium