使用.clear()或.send_keys()后,当按钮被禁用时,如何使用Python Selenium单击(绕过)提交按钮?

使用.clear()或.send_keys()后,当按钮被禁用时,如何使用Python Selenium单击(绕过)提交按钮?,python,python-3.x,selenium,web-scraping,Python,Python 3.x,Selenium,Web Scraping,正如标题所述,当按钮在使用方法清除或发送键后被禁用时,如何使用硒单击按钮 之前: 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 这是我打开时的页面状态,它是url。。。但是,在我运行代

正如标题所述,当按钮在使用方法
清除
发送键后被禁用时,如何使用
单击
按钮


之前:

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


这是我打开时的页面状态,它是
url
。。。但是,在我运行代码找到
文本框和
替换
它的值之后,元素在我
清除
它的内容或使用
发送(send_)键向它写入内容之后立即被禁用


之后:

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


代码:

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
我的问题是:

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
如何绕过此网站保护并按下
Continuar
按钮

我曾想过禁用
JS
,但整个网站都依赖它来生成所需的文档。。错误的选择

所以我考虑使用按钮属性来模拟按下按钮。。。只是不知道这是否可能,或者我怎么能做到

另一个选项是仅阻止禁用按钮的
JS
,该按钮可能使用
inspect元素和
网络工具来映射命令的来源

那么,有什么办法可以实现这一点呢


注:我不能给出URL,因为它需要我的登录数据。

好的,所以你不能通过正常方式直接这样做。Selenium WebDriver用于模拟浏览器的实际使用。但是,也可以使用execute_脚本函数。(JavaSelenium有一个内置的JavascriptExecutor类,我假设这是python的版本。)execute_脚本函数允许Selenium执行与浏览器交互的人无法执行的任务

driver.execute_script("document.getElementById('buttonid').click()")

或者类似的方法应该奏效。希望这能帮到你。

好的,所以你不能通过正常的方式直接做这件事。Selenium WebDriver用于模拟浏览器的实际使用。但是,也可以使用execute_脚本函数。(JavaSelenium有一个内置的JavascriptExecutor类,我假设这是python的版本。)execute_脚本函数允许Selenium执行与浏览器交互的人无法执行的任务

driver.execute_script("document.getElementById('buttonid').click()")

或者类似的方法应该奏效。希望这对您有所帮助。

如果您没有使用selenium和javascript的解决方案,您可以使用Sikuli概念。要单击该元素,请获取“Continuar”按钮的图像并将其保存在resources文件夹中

String elementImg=Path of the Image;
    screen.click(elementImg);

如果您没有使用selenium和javascript获得任何解决方案,那么可以使用Sikuli概念。要单击该元素,请获取“Continuar”按钮的图像并将其保存在resources文件夹中

String elementImg=Path of the Image;
    screen.click(elementImg);

我可以使用
driver.execute_脚本(“document.getElementById('txtValor4')绕过这个问题。‌​value=123.45“
,将值传递到文本框中,这样按钮就不会被禁用,我可以按
继续
按钮

即使绕过这个,结果也不是预期的!我输入的值应该通过某种兴趣进行更正。但绕过此选项,该值不会被更正

今天,询问该程序的用户告诉我,每当我更改此
文本框中的值时,我必须按下
计算
按钮

因此,我可以使用以下方法解决我的问题,而不是低效地绕过此
禁用
方法:

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()
通过这种方式,税值会根据利息进行更正,网站会生成
.pdf
和我期望的准确值


非常感谢所有花时间和精力帮助我的人。

我可以使用
driver.execute_脚本(“document.getElementById('txtValor4')绕过这个问题。‌​value=123.45“
,将值传递到文本框中,这样按钮就不会被禁用,我可以按
继续
按钮

即使绕过这个,结果也不是预期的!我输入的值应该通过某种兴趣进行更正。但绕过此选项,该值不会被更正

今天,询问该程序的用户告诉我,每当我更改此
文本框中的值时,我必须按下
计算
按钮

因此,我可以使用以下方法解决我的问题,而不是低效地绕过此
禁用
方法:

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()
通过这种方式,税值会根据利息进行更正,网站会生成
.pdf
和我期望的准确值


非常感谢所有花时间和精力帮助我的人。

听起来好像是因为表单验证而禁用了它,因为它不喜欢您在文本字段中输入的值。可能是文本字段未注册更改。您可以尝试在发送_键后单击文本区域的外部,以便使其“接受”更改。不幸的是,这不是问题所在!我在
clear()
send_keys()
方法之后拍摄了这张照片。我可以找到元素,清除它的值并插入正确的值。
clear()
send_keys()
方法是我问题的根源。当我运行它们时,某些东西触发了站点的“禁用按钮”保护方法。。。但是如果我使用
b.send_键(keys.BACKSPACE)
它可以工作!我可以在不禁用按钮的情况下清除内容。。。但是当我使用
send_键('123,45')
(带值)时,按钮会被禁用。听起来它好像是由于表单验证而被禁用的,因为它不喜欢您在文本字段中输入的值。可能是文本字段未注册更改。您可以尝试在send_键后单击文本区域的外部,以使其“接收”文本