【问题标题】:sendKeys() does not pass the character "@"sendKeys() 不传递字符“@”
【发布时间】:2021-01-25 21:59:32
【问题描述】:

我正在使用硒 3.6.0。我运行了一些基本测试(登录到 Stackoverflow 页面)。但是,当我发送电子邮件时,字符“@”没有传递。而不是它,在我看来,它从缓冲区中放入了一些值。

package Cucumerframework.steps;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.Assert;

import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;


public class StepsClass {

    WebDriver driver;

    @Before()
    public void setup() {
        System.setProperty("webdriver.chrome.driver",
                "C:\\Users\\WCodeKemalK\\Cucumber\\Cucumerframework\\target\\test-classes\\Resources\\chromedriver.exe");
        this.driver = new ChromeDriver();
        this.driver.manage().window().maximize();
        this.driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
    }

    @Given("^User navigates to stackoverflow website$")
    public void user_navigates_to_stackoverflow_website() throws Throwable {
        driver.get("https://stackoverflow.com/");
    }

    @Given("^User clicks on the login button on homepage$")
    public void user_clicks_on_the_login_button_on_homepage() throws Throwable {
        driver.findElement(By.xpath("/html/body/header/div/ol[2]/li[2]/a[1]")).click();
    }

    @Given("^User enters a valid username$")
    public void user_enters_a_valid_username() throws Throwable {
        driver.findElement(By.xpath("//*[@id=\"email\"]")).sendKeys("testmail@gmail.com");
    }

    @Given("^User enters a valid password$")
    public void user_enters_a_valid_password() throws Throwable {
        
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys("xxxxxxx");
    }

    @When("^User clicks on the login button$")
    public void user_clicks_on_the_login_button() throws Throwable {
        driver.findElement(By.xpath("//*[@id=\"submit-button\"]")).click();
    }

    @Then("^User should be taken to the successful login page$")
    public void user_should_be_taken_to_the_successful_login_page() throws Throwable {
        Thread.sleep(3000);
        WebElement askQuestionsButton = driver.findElement(By.xpath("//a[contains (text(), )]"));
        Assert.assertEquals(true, askQuestionsButton.isDisplayed());
    }
}

这是我得到的: https://ibb.co/k35WL3N

【问题讨论】:

  • 您是否在启动测试的计算机上使用英文键盘布局?如果没有,那么“@”可能会触发另一个键(在 enligh 键盘上位于 @ 位置的那个键)
  • @LaurentBristiel 我正在使用标准键盘

标签: automated-tests selenium-chromedriver qa


【解决方案1】:

您的问题已多次在此论坛上报告。无论您是否“使用标准键盘”,问题肯定是您计算机上的某种“键盘语言设置”,它将“@”解释为“从剪贴板复制”命令。在 Selenium 之外的其他程序中尝试它,例如记事本,或在 Chrome 的网页表单页面中“手动”尝试;我打赌你也不能在这些程序中输入“@”。

ETA:看起来我的假设有一部分是错误的;现在我猜你代码中的“@”不是实际的 ASCII @ 代码,而是另一个看起来像这样的字符代码。我仍然怀疑问题的根源是键盘/语言/计算机设置。

【讨论】:

  • 在任何其他应用程序中,在记事本、网络应用程序等中都会显示字符“@”。但是,幸运的是,我通过从网络上复制这个字符解决了这个问题,我在维基百科上找到了它,复制它现在可以工作了。感谢您的回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 2016-09-09
  • 1970-01-01
相关资源
最近更新 更多