selenium-webdriver - 使用 Selenium Webdriver 发送多个空格/空格似乎是不可能的
问题描述
你能告诉我如何使用 sendkeys 或类似的东西发送多个空格/空格。我正在尝试测试是否接受在其他字符之间使用多个空格来创建用户名(比如说“用户名”)。我没有成功使用字符串、使用 sendkeys“用户名”或多次使用 sendkeys(Keys.SPACE)。它总是减少到一个空格。非常感谢。
解决方案
尝试sendKeys()
使用 Actions 的方法发送它。
public void sendTextAction(By locator, String text){
Actions action = new Actions(driver);
clickVisible(locator);
action.sendKeys(text).build().perform();
}
如果这仍然不起作用,请尝试多次使用此方法,即发送“用户名”试试这个:
sendTextAction(elementLocator,"user");
sendTextAction(elementLocator," ");
sendTextAction(elementLocator," ");
sendTextAction(elementLocator," ");
sendTextAction(elementLocator,"name");
但首先试试这个
sendTextAction(elementLocator,"user name");
推荐阅读
- ag-grid - ag-grid 'IToolPanel' 已声明,但它的值从未被读取
- google-sheets - 按降序填充最近 30 个日期的列
- azure-data-lake - U-SQL 相关子查询
- android - xml 布局的一个组件不显示
- python - 如何使用 Python xlwings 将大量列表复制到 Excel
- cordova - 无法从科尔多瓦视频编辑器插件访问缩略图
- python - 单选按钮和 webapp2
- elasticsearch - 在 elasticsearch 中过滤聚合 doc_count
- javascript - 关于使用 jquery 动态生成和删除 html 元素
- python - 使用 python 从 db 中获取最后插入的值