Исключение в потоке «основной» java.lang.ClassCastException: класс org.openqa.selenium.remote.ShadowRoot нельзя привести ⇐ JAVA

Программисты JAVA общаются здесь
Anonymous
Исключение в потоке «основной» java.lang.ClassCastException: класс org.openqa.selenium.remote.ShadowRoot нельзя привести

Сообщение Anonymous »

Я пытался написать эту программу для Shadow DOM в Selenium, но получаю эту ошибку. Любые решения, как исправить эту ошибку.
Пробовал разные способы переписать код и найти, где ошибка сохраняется, но ошибка все равно возникает.
Исключение
Exception in thread "main" java.lang.ClassCastException: class org.openqa.selenium.remote.ShadowRoot cannot be cast to class org.openqa.selenium.WebElement (org.openqa.selenium.remote.ShadowRoot and org.openqa.selenium.WebElement are in unnamed module of loader 'app')
at practice.ShadowDomExample.main(ShadowDomExample.java:25)

CODE
package practice;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class ShadowDomExample {

@SuppressWarnings("deprecation")
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

driver.get("https://books-pwakit.appspot.com/");
driver.manage().window().maximize();

WebElement root_ShadowHost = driver.findElement(By.cssSelector("book-app[apptitle='BOOKS']"));

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement shadowDOM = (WebElement) js.executeScript("return arguments[0].shadowRoot", root_ShadowHost);

WebElement appheader = shadowDOM.findElement(By.tagName("app-header"));

WebElement apptoolbar = appheader.findElement(By.cssSelector("app-toolbar.toolbar-bottom"));

WebElement bookinputdecorator = apptoolbar.findElement(By.tagName("book-input-decorator"));

WebElement searchBox = (WebElement) js.executeScript("return arguments[0].querySelector(\"input[aria-label='Search Books']\")", bookinputdecorator);

searchBox.sendKeys("Testing");

System.out.println("Succesfully typed into the search box ");

driver.quit();
}
}


Подробнее здесь: https://stackoverflow.com/questions/782 ... nqa-seleni

Вернуться в «JAVA»