[英]How to select the "Select with computer" button on Instagram and upload images using send_keys() method using Selenium (Python)
[英]How can I click (bypass) a submit button using Python Selenium, when the button gets disabled after using .clear() or .send_keys()?
如标题所述,当使用clear
或send_keys
方法后按钮被“ disabled
”时,如何使用Selenium
.click()
button
?
之前:
当我打开它的url
时,这就是页面状态...但是随后,在我运行代码以查找textbox
并replace
其值之后,立即在clear
内容或编写内容后立即disabled
了该元素(也许是某种JS
)它使用send_keys
。
后:
码:
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 element
和network tools
映射命令来自何处...
那么有什么办法可以做到这一点?
ps:我无法提供URL,因为它需要我的登录数据。
好的,因此您无法通过常规方式直接执行此操作。 Selenium WebDriver旨在模拟浏览器的实际使用。 但是,可以使用execute_script函数。 (Java Selenium具有内置的JavascriptExecutor类,我认为这是python的版本。)execute_script函数允许Selenium执行人类与浏览器进行交互无法执行的任务。
driver.execute_script("document.getElementById('buttonid').click()")
或者遵循这些原则的东西应该起作用。 希望对您有所帮助。
如果您无法使用Selenium和javascript获得任何解决方案,则可以使用Sikuli概念。 要单击该元素,请拍摄“ Continuar”按钮的图像并将其保存在资源文件夹中。
String elementImg=Path of the Image;
screen.click(elementImg);
我可以使用driver.execute_script("document.getElementById('txtValor4').value = 123.45")
绕过此操作,将值传递到文本框中,因此该按钮没有被disabled
,我可以按Continue
按钮。
即使绕开了它,结果也不是预期的! 我输入的值应该会因某种兴趣而更正。 但是绕过这个值不会被更正。
今天,询问程序的用户告诉我,每次我更改此文本textbox
的值时,都必须按“ Calculate
按钮。
因此,与其有效地绕过此disable
方法,不如使用以下方法解决问题:
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
。
非常感谢所有花费时间和精力来帮助我的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.