1

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

DigiMon
  • 17
  • 1
  • 3

1 Answers1

0

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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried using the 'EC' driver you suggested, but it still fails. and goes to the next line to the pop up accept code immediately - meaning no popup and program failing. 'web' is my driver btw. `service = EdgeService(executable_path=EdgeChromiumDriverManager().install()) web = webdriver.Edge(service=service)` `web.switch_to.alert.accept()` – DigiMon Apr 20 '22 at 13:28
  • This is the error I am getting before `...alert.accept()` Error: `DevTools listening on ws://127.0.0.1:52298/devtools/browser/3086466f-8830-4e3d-85fd-63205690a019 [6048:3312:0420/100524.086:ERROR:fallback_task_provider.cc(124)] Every renderer should have at least one task provided by a primary task provider. If a "Renderer" fallback task is shown, it is a bug. If you have repro steps, please file a new bug and tag it as a dependency of crbug.com/739782.` – DigiMon Apr 20 '22 at 14:13
  • Error (Continued): `[6048:3312:0420/100529.705:ERROR:device_event_log_impl.cc(214)] [10:05:29.704] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) [6048:17784:0420/100623.097:ERROR:util.cc(132)] Can't create base directory: C:\Program Files\Microsoft\EdgeUpdater [8292:17068:0420/100723.076:ERROR:gpu_init.cc(460)] Passthrough is not supported, GL is disabled, ANGLE is` – DigiMon Apr 20 '22 at 14:14