

Сообщений в теме: 2
#1
Отправлено 25 мая 2018 - 07:21
java+selenium web driver (ie). Мне нужно кликнуть на элемент
скрин.png 342,12К
1 Количество загрузок:, но selenium не видит элементы внутри <body>. Прошу подсказать, почему "не видит" и как мне обратиться к нужному элементу. Пробовал обращаться через xpath, className, tagName - тщетно. Для понимания картины:

try{
WebElement element = driver.findElement(By.xpath("html"));
List<WebElement> childs = element.findElements(By.xpath("./*"));
Iterator it = childs.iterator();
while(it.hasNext()) {
WebElement elem = (WebElement) it.next();
driver.manage().timeouts().implicitlyWait(1, SECONDS);
System.out.println(elem.getTagName() + " ");
}
//System.out.println(element.getTagName());
}catch (NoSuchElementException e){
System.out.println("Oooppppss. NoSuchElement");
}
Консоль:
head
body
try{
WebElement element = driver.findElement(By.xpath("html/head"));
List<WebElement> childs = element.findElements(By.xpath("./*"));
Iterator it = childs.iterator();
while(it.hasNext()) {
WebElement elem = (WebElement) it.next();
driver.manage().timeouts().implicitlyWait(1, SECONDS);
System.out.println(elem.getTagName() + " ");
}
}catch (NoSuchElementException e){
System.out.println("Oooppppss. NoSuchElement");
}
Консоль:
title
meta
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element is no longer valid ...
try{
WebElement element = driver.findElement(By.xpath("html/body"));
List<WebElement> childs = element.findElements(By.xpath("./*"));
Iterator it = childs.iterator();
while(it.hasNext()) {
WebElement elem = (WebElement) it.next();
driver.manage().timeouts().implicitlyWait(1, SECONDS);
System.out.println(elem.getTagName() + " ");
}
}catch (NoSuchElementException e){
System.out.println("Oooppppss. NoSuchElement");
}
В консоли пусто (в смысле вот это "System.out.println(elem.getTagName() + " ")" ничего не вывело).
#2
Отправлено 04 июня 2018 - 09:14
выведите на консоль getpagesource
#3
Отправлено 05 июня 2018 - 10:33
выведите на консоль getpagesource
Да, страница после запуска выполняла обновление, поэтому искомый элемент и не был обнаружен. Помогла вставка данного кода после вызова driver.get("...");:
String currentWindow = driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles()){
if(!winHandle.equals(currentWindow)){
driver.switchTo().window(winHandle);
}
}
Спасибо.
Количество пользователей, читающих эту тему: 0
0 пользователей, 0 гостей, 0 анонимных