我正在学习Selenium WebDriver,有一个问题。 我想在Amazon网站上搜索带有uppercaste的“汽车”。我使用keyDown,但是它不起作用。该测试程序仅适合小写的“汽车”。
HTML代码:
<input id="twotabsearchtextbox" value="" name="field-keywords" autocomplete="off" placeholder="" class="nav-input" dir="auto" tabindex="19" type="text">
JAVA代码:
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Downloads\\geckodriver-v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.amazon.com/ref=nav_logo");
WebElement search = driver.findElement(By.id("twotabsearchtextbox"));
Actions builder2 = new Actions(driver);
Action seria = builder2
.moveToElement(search)
.click()
.keyDown(search, Keys.SHIFT)
.sendKeys(search, "car")
.keyUp(search, Keys.SHIFT)
.sendKeys(Keys.ENTER)
.build();
seria.perform();
}
Firefox版本:61.0.1
Geckodriver版本:0.21.0
感谢您的帮助:)
答案 0 :(得分:0)
seria.keyDown(search, Keys.SHIFT).sendKeys("car").keyDown(search, Keys.SHIFT).build().perform();
此代码应适合您。