Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

automated tests - sendKeys() does not pass the character "@"

I am using selenium 3.6.0. and I run some basic test (login to the Stackoverflow page). But, when I am sending email, character "@" is not passed. Instead of it, it looks like for me that it puts some values from buffer.

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("[email protected]");
    }

    @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());
    }
}

Here is what I get: https://ibb.co/k35WL3N

question from:https://stackoverflow.com/questions/65893021/sendkeys-does-not-pass-the-character

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your problem has been reported on this forum repeatedly. Regardless of whether you're "using a standard keyboard", the problem is surely some kind of "keyboard language settings" on your computer which interpret the "@" as a "copy from clipboard" command. Try it outside of Selenium in some other program, e.g. Notepad, or try it "by hand" in a web form page in Chrome; I bet you can't type a "@" in those programs either.

ETA: Looks like my hypothesis was partly wrong; now I'd guess that the "@" in your code wasn't an actual ASCII @ code, but rather another character code that looks like that. I still suspect that the source of the problem is keyboard/language/computer settings.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...