我尝试使用 sendKeys()
在 amazon.in 网站搜索栏中输入大写字母字符串(使用 KeyDown),但在搜索栏上看不到该文本。我没有看到任何错误。我使用 Debug模式,然后我也可以找到任何错误。
问题:
如何解决这个问题?
如何自己调试并发现问题?
为了调试,我在下面的行上放置了一个断点,然后使用单步选项来运行每一行。
mouseAction.moveToElement(elementLocation).build().perform();
public class MouseActions {
public static void main (String [] args){
System.setProperty ("webdriver.chrome.driver","C:\\Users\\tokci\\Documents\\Selenium\\drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.amazon.in/");
Actions mouseAction = new Actions(driver);
//this mouse action works
WebElement elementLocation = driver.findElement(By.xpath("//a[@id='nav-link-yourAccount']"));
mouseAction.moveToElement(elementLocation).build().perform();
//below code does not work
WebElement keysLocation = driver.findElement(By.xpath("//input[@id='twotabsearchtextbox']"));
mouseAction.keyDown(Keys.SHIFT).moveToElement(keysLocation).sendKeys("shoes").build().perform();
}
}
最佳答案
keysLocation
是一个 input
元素,您可以使用 .sendKeys()
而无需使用 mouseAction
,如下所示它有效:-
keysLocation.sendKeys(Keys.SHIFT, "shoes");
希望对你有帮助..:)
关于java - KeyDown() 、sendKeys() 在 Selenium 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38216903/