java sendkeys方法,Selenium WebDriver:我想在字段中覆盖值,而不是使用Java使用sendKeys附加到它...

"在WebDriver中遇到无法清空输入字段的问题,因为使用clear()方法会导致页面抛出10到100之间的长度限制错误。一种解决方案是先通过选择所有文本并发送新的键序列来覆盖字段值,例如:element.sendKeys(Keys.chord(Keys.CONTROL, "a"), ""55""); 这样可以避免错误并成功替换字段内的值。"
摘要由CSDN通过智能技术生成

In WebDriver, if I use sendKeys it will append my string to the value that already exists in the field. I can't clear it by using clear() method because the second I do that, the webpage will throw an error saying that it has to be between 10 and 100. So I can't clear it or an error will be thrown before I can put in the new value using sendKeys, and if I sendKeys it just appends it to the value already there.

Is there anything in WebDriver that lets you overwrite the value in the field?

解决方案

I think you can try to firstly select all the text in the field and then send the new sequence:

from selenium.webdriver.common.keys import Keys

element.sendKeys(Keys.chord(Keys.CONTROL, "a"), "55");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值