我正在测试的网站有一个文本框来输入位置。当我输入字符时,Google API会在文本框下方发送与此字符匹配的位置列表。这是snapshot of autocomplete options
我试图在selenium中自动化这个场景。但问题是当我使用textbox.sendkeys(" text")时,不会从Google API填充位置列表。
我尝试过隐式和显式等待,计时器高达200秒,但仍然无法正常工作。我试过,在sendkeys()之后单击(),在sendkeys()之后单击KEYS.Arrow_down并单击鼠标。但它似乎仍然无法发挥作用。 请提供您的建议。
这是我的测试代码:
public void add_inv() throws Exception{
commands.implicitwait(driver);
Inventory.btn_addinventory(driver).click();
Inventory.btn_addlocation(driver).click();
Inventory.txt_locAddr(driver).click();
commands.implicitwait(driver);
Inventory.txt_locAddr(driver).click();
Inventory.txt_locAddr(driver).sendKeys("bangalore", Keys.ARROW_DOWN);
commands.setDefaultTimeout(100);
commands.implicitwait(driver);
String loctext = driver.findElement(By.xpath("html/body/div[3]/div[1]/span[3]")).getText();
System.out.println("loctext: "+loctext);
}
答案 0 :(得分:0)
尝试使用下面给出的动作类。
public void add_inv() throws Exception{
commands.implicitwait(driver);
Inventory.btn_addinventory(driver).click();
Inventory.btn_addlocation(driver).click();
Inventory.txt_locAddr(driver).click();
commands.implicitwait(driver);
Inventory.txt_locAddr(driver).click();
//Inventory.txt_locAddr(driver).sendKeys("bangalore", Keys.ARROW_DOWN);
new Actions(driver).sendKeys(Inventory.txt_locAddr(driver),"bangalore").perform();
String loctext = driver.findElement(By.xpath("html/body/div[3]/div[1]/span[3]")).getText();
System.out.println("loctext: "+loctext);
}