【问题标题】:Sending multiple whitespace / blankspace with Selenium Webdriver appears impossible使用 Selenium Webdriver 发送多个空格/空格似乎是不可能的
【发布时间】:2021-07-29 12:49:55
【问题描述】:

您能告诉我如何使用 sendkeys 或类似的东西发送多个空格/空格。我正在尝试测试是否接受在其他字符之间使用多个空格来创建用户名(比如说“用户名”)。我没有成功使用字符串、使用 sendkeys“用户名”或多次使用 sendkeys(Keys.SPACE)。它总是减少到一个空格。非常感谢。

【问题讨论】:

  • 我的回答能解决你的问题吗?

标签: selenium-webdriver whitespace sendkeys


【解决方案1】:

尝试使用操作通过sendKeys() 方法发送它。

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");

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2010-12-06
    相关资源
    最近更新 更多