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

2024-09-24 00:28:49 发布

您现在位置:Python中文网/ 问答频道 /正文

正如标题所说,当使用方法clearsend_keys后,按钮得到“disabled”,我如何使用.click()abutton?在


之前:

enter image description here


这是我打开页面时的状态url。。。但是在我运行代码找到textboxreplace的值之后,元素就在我clear它的内容之后得到{}(可能是某种形式的{}),或者使用send_keys向其写入内容。在


之后:

enter image description here


代码:

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

我的问题是:

How can I bypass this website protection and press the Continuar button?

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

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

另一个选项是只阻止JS,它使用inspect elementnetwork tools禁用命令的按钮映射。。。在

那么有什么方法可以达到这个目的吗?在

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


Tags: the方法代码txtsend内容valuejs
3条回答

好吧,所以你不能直接用普通的方法。Selenium WebDriver是用来模拟浏览器的实际使用的。但是,可以使用execute_script函数。(javaselenium有一个内置的JavascriptExecutor类,我假设这是python的版本。)execute_script函数允许Selenium执行人类与浏览器交互无法完成的任务。在

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

或者说应该有办法。希望对你有帮助。在

我可以使用driver.execute_script("document.getElementById('txtValor4').‌​value = 123.45")来绕过它,将值传递到文本框中,因此按钮没有disabled,我可以按Continue按钮。在

即使绕过这个,结果也不是预期的!我输入的值应该被某种兴趣所修正。这个值没有被修正,但是没有被修正。在

今天,询问程序的用户告诉我,每次我更改textbox内的值,我必须按Calculate按钮。在

因此,我可以使用以下方法来解决我的问题:

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与我期望的值完全一致。在

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

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

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

相关问题 更多 >