我使用的是selenium 3.6.0。然后运行一些基本测试(登录到Stackoverflow页面)。但是,当我发送电子邮件时,不会传递字符"@“。而不是它,它看起来像是从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("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());
}
}下面是我得到的:https://ibb.co/k35WL3N
发布于 2021-01-27 00:31:18
您的问题已在此论坛上反复报告。不管你是否“使用标准键盘”,问题肯定是你计算机上的某种“键盘语言设置”,它将"@“解释为”从剪贴板复制“命令。在Selenium之外的其他程序中尝试它,例如记事本,或者在Chrome的网页表单页面中“手动”尝试它;我打赌你也不能在这些程序中输入"@“。
ETA:看起来我的假设有一部分是错的;现在我猜你代码中的"@“不是一个真正的ASCII @代码,而是另一个看起来像这样的字符代码。我仍然怀疑问题的根源在于键盘/语言/计算机设置。
https://stackoverflow.com/questions/65893021
复制相似问题