Automated tests sendKeys()不传递字符“0”@&引用;

Automated tests sendKeys()不传递字符“0”@&引用;,automated-tests,selenium-chromedriver,qa,Automated Tests,Selenium Chromedriver,Qa,我正在使用selenium 3.6.0。我运行了一些基本测试(登录Stackoverflow页面)。但是,当我发送电子邮件时,字符“@”没有传递。相反,在我看来,它从缓冲区中放入了一些值 package Cucumerframework.steps; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.open

我正在使用selenium 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(), Ask Question)]"));
        Assert.assertEquals(true, askQuestionsButton.isDisplayed());
    }
}
以下是我得到的:

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


埃塔:看来我的假设部分是错的;现在我猜代码中的“@”不是一个真正的ASCII@代码,而是另一个类似的字符代码。我仍然怀疑问题的根源是键盘/语言/计算机设置。

您是否在启动测试的计算机上使用英语键盘布局?如果没有,那么“@”可能会触发另一个键(在英语键盘上@位置的键)@LaurentBristiel我在任何其他应用程序中使用标准键盘,在记事本、网络应用程序等中都会显示“@”字符。然而,幸运的是,我通过从web复制这个字符解决了这个问题,我在wikipedia上找到了它,复制它,现在就可以工作了。谢谢你的回答。