0

html confirmar button

Not sure about why, but maybe it is something like JS or hidden element.

I need to click on "Confirmar" button, but for some reason its not clickable.

This button is into a diferent "block" then the others that I fill in the form.

this the html of this button

<input type="submit" name="ctl00$WpModaisCrm1$ctl03$btnRegistrarProtocolo" value="Confirmar" id="btnRegistrarProtocolo" class="btn btn-primary pull-right" autocomplete="off">

the "Cancelar" button html is:

<input type="submit" name="ctl00$WpModaisCrm1$ctl03$btnCancelarProtocolo" value="Cancelar" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$WpModaisCrm1$ctl03$btnCancelarProtocolo&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_WpModaisCrm1_ctl03_btnCancelarProtocolo" class="btn btn-primary button-padding" data-dismiss="modal" autocomplete="off">

and there is an hidden element with this HTML

<input type="submit" name="ctl00$WpModaisCrm1$ctl03$btnCarregarUcProtocoloAtendimento" value="" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$WpModaisCrm1$ctl03$btnCarregarUcProtocoloAtendimento&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="btnCarregarUcProtocoloAtendimento" style="display: none" autocomplete="off">

HTML

Form

code:

confirmar = driver.find_element_by_id("btnRegistrarProtocolo")
print(confirmar.is_enabled()) # return True

print(confirmar.is_displayed()) # return True
print(confirmar.is_selected()) # return False

confirmar.submit() # doesn't work
confirmar.click() # doesn't work

click() and submit() does nothing...

EDIT

I also can't reach the "Confirmar" button usign "Tab", only with mouse

Pedro Roque
  • 1
  • 1
  • 2
  • Please add the code you have tried that is not working. Also see: https://stackoverflow.com/help/how-to-ask – Jortega Jan 03 '20 at 20:38
  • post the
    tag, and try/catch the .click() and show exception, if any.
    – pcalkins Jan 03 '20 at 21:00
  • what doesn't work? does it just not do anything? or are you getting an exception? if it's not doing anything, it seems likely that the form data you are trying to submit is not valid or initialized properly. – crookedleaf Jan 03 '20 at 21:13
  • Jortega I'll post here at monday pcalkins I'll post here at monday, no exception when I try click crookedleaf Just nothing happens, no exception :( I also can't reach the "Confirmar" button usign "Tab", only with mouse, not sure if it can help with other ideas – Pedro Roque Jan 04 '20 at 19:01

2 Answers2

1

I know I am a bit late here, but this particular issue with interactability - even in the case that an element is found in the DOM as you have found - can propagate because of two issues in my experience; either other JS elements are actually "in the way" with respect to their position in the DOM or you are dealing with unruly element types like an input.

The cure in either case is typically to call directly to JS rather than through Python via execute_script() as such:

confirmar = driver.find_element_by_id("btnRegistrarProtocolo")
driver.execute_script('arguments[0].click();', confirmar)

If you find this doesn't work it will be because there is a multiplicity of elements with the same selector on the page in which case you should locate the element via XPath. You can test this with checking length on find_elements() like this:

registrars = driver.find_elements(by='id','btnRegistrarProtocolo')

or

registrars = driver.find_elements_by_id('btnRegistrarProtocolo')


if len(registrars) > 1:
    print('Wow I might've been clicking the wrong element this whole time!')

As a normative standard, I always utilize XPath for locating elements simply because if used correctly it leaves little ambiguity in the way of what you are interacting with.

  • This is the most concise and updated answer: in my case `driver.execute_script('arguments[0].click();', confirmar)` did the trick. Thanks! – Dan Sep 28 '21 at 01:54
0

The element with text as Confirmar is a JavaScript enabled element so you have 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#btnRegistrarProtocolo[value='Confirmar']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='btnRegistrarProtocolo' and @value='Confirmar']"))).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
  • Tried both, using Xpath and CSS Selector, but nothing happens, any other idea? – Pedro Roque Jan 03 '20 at 22:13
  • @PedroRoque Can you replace `click()` with `submit()` for both the locators and retest and let me know the status please? – undetected Selenium Jan 03 '20 at 22:17
  • No exception appears with .click() Using submit a "pop up" with the "loading" mensage appears, but the form doesnt give the ccorrect response. I also can't reach the "Confirmar" button usign "Tab", only with mouse – Pedro Roque Jan 04 '20 at 18:59