交互我試圖執行下面的Selenium Web驅動程序腳本,但我得到org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
錯誤幾次(並非所有的時間)。有時在循環中第一次迭代,有時在2次迭代中,有時沒有開始循環。它打印所有可用的項目算錯,但乳清試圖點擊項目,它顯示Element is not currently visible...
org.openqa.selenium.ElementNotVisibleException:元素當前不可見,因此可能不會與
public void pickitems() throws Exception
{
Webdriver driver = new firefoxdriver();
driver.get("http://www.bigbasket.com");
driver.manage().window().maximize();
//Selecting Location
List<WebElement> list = driver.findElement(By.id("ftv-city-popup")).findElements(By.tagName("button"));
int location = r.nextInt(list.size());
list.get(location).click();
//Selection random Category from left panel through list
Thread.sleep(30000);
List<WebElement> xyz = driver.findElement(By.id("uiv2-main-menu")).findElements(By.className("top-category"));
System.out.println(xyz.size());
Random r = new Random();
int category = r.nextInt(xyz.size());
xyz.get(category).click();
for (int i = 0; i < 3; i++) {
Thread.sleep(30000);
List<WebElement> availableItems = driver.findElements(By.cssSelector("a.uiv2-add-button.a2c"));
System.out.println(availableItems.size());
if (availableItems.size() > 0)
{
int selectItem = r.nextInt(availableItems.size());
availableItems.get(selectItem).click();
}
else
{
Thread.sleep(30000);
List<WebElement> availableItems2 = driver.findElements(By.cssSelector("a.uiv2-add-button.a2c"));
if (availableItems2.size() == 0) {
System.out.println("No more items are available. Sorry for the inconvenience");
}
else {
Assert.fail("Unable to select items. May be page loading issue");
}
}
}
}
}
感謝。這解決了我的問題。 – 2015-02-26 05:14:05
@JakeW。很高興幫助你 – Saifur 2015-02-26 13:29:47
你能幫我把這個命令轉換成JS嗎?我有同樣的問題,但我在Node.JS的量角器中使用。謝謝@Saifur – 2016-06-09 11:46:04