As the title says, how can I .click()
a button
using Selenium
, when the button gets " disabled
" after using the method clear
or send_keys
?
Before:
That's the page status when I open it's url
... but then right after I run my code to find the textbox
and replace
it's value, the element gets disabled
(maybe by some sort of JS
) right after I clear
it's content or write something to it using send_keys
.
After:
Code:
txt_value = driver.find_element_by_xpath('//input[@id="txtValor4"]')
txt_value.clear() #this disables the button
txt_value.send_keys(str(123,45)) #this also disables the button
My question is:
How can I bypass this website protection and press the
Continuar
button?
I thought about disabling JS
, but the whole website relies on it to produces the requires documents.. wrong alternative.
So I thought about using the button properties to simulate the pressing of the button... just don't know if it's possible, or how I could do this.
Another option was blocking only the JS
that disables the button maybe mapping where the command comes from using the inspect element
and network tools
...
So is there any way to achieve this?
ps.: I can't give the URL because it requires my login data.
Ok, so you can't directly do this through normal means. Selenium WebDriver is made to simulate real use of a browser. It may be possible however to use the execute_script function. (Java Selenium has a built in JavascriptExecutor class, I assume this is python's version.) The execute_script function allows Selenium to perform tasks that a human interacting with a browser can't do.
driver.execute_script("document.getElementById('buttonid').click()")
Or something along those lines should work. Hope that helps you out.
If you don't get any solution with selenium and javascript, you can use Sikuli concept. To click that element, take the image of the 'Continuar' button and save it in resources folder.
String elementImg=Path of the Image;
screen.click(elementImg);
I could bypass this using driver.execute_script("document.getElementById('txtValor4').value = 123.45")
, to pass the values into the textbox, so the button didn't got disabled
and I could press the Continue
button.
Even bypassing this, the result wasn't the expected! The value that I entered was supposed to be corrected by some sort of interest. But bypassing this, the value isn't corrected.
Today the user that asked the program told me that everytime I change the value inside this textbox
, I must press the Calculate
button.
So, instead of inefficiently bypassing this disable
method, I could solve my problem using:
b = driver.find_element_by_xpath('//input[@id="txtValor4"]')
b.clear()
b.send_keys('123.45')
driver.find_element_by_xpath('//input[@id="btnCalcular4"]').click()
driver.find_element_by_xpath('//input[@id="btnContinuar4"]').click()
This way the tax value is corrected by interest and the website generate the .pdf
with the exact value that I was expecting.
Many thanks for everyone that put some time and effort trying to help me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.