В процессе поиска кнопки Очистить данные внутри Всплывающее окно Очистить данные просмотра, которое появляется при доступе к URL-адресу chrome://settings/clearBrowserData через Selenium. Мне не удалось найти следующий элемент:
Код: Выделить всё
#shadow-root (open)
[img]https:// i.sstatic.net/RUUI6.png[/img]
При использовании Selenium приведены мои пробные версии кода и обнаруженные связанные с ними ошибки:
- Попытка 1:
Код: Выделить всё
WebElement root5 = shadow_root4.findElement(By.tagName("settings-privacy-page"));
Ошибка:
Код: Выделить всё
Exception in thread "main" org.openqa.selenium.JavascriptException: javascript error: b.getElementsByTagName is not a function
Код: Выделить всё
WebElement root5 = shadow_root4.findElement(By.cssSelector("settings-privacy-page"));
- Ошибка:
Код: Выделить всё
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"settings-privacy-page"}
Код: Выделить всё
WebElement root5 = (WebElement)((JavascriptExecutor)shadow_root4).executeScript("return document.getElementsByTagName('settings-privacy-page')[0]");
- Ошибка:
Код: Выделить всё
Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to org.openqa.selenium.JavascriptExecutor
В случае, если это полезно, начальный блок кода (до строка выше) работает отлично:
Код: Выделить всё
driver.get("chrome://settings/clearBrowserData");
WebElement root1 = driver.findElement(By.tagName("settings-ui"));
WebElement shadow_root1 = expand_shadow_element(root1);
WebElement root2 = shadow_root1.findElement(By.cssSelector("settings-main#main"));
WebElement shadow_root2 = expand_shadow_element(root2);
WebElement root3 = shadow_root2.findElement(By.cssSelector("settings-basic-page[role='main']"));
WebElement shadow_root3 = expand_shadow_element(root3);
WebElement root4 = shadow_root3.findElement(By.cssSelector("settings-section[page-title='Privacy and security']"));
WebElement shadow_root4 = expand_shadow_element(root4);
Подробнее здесь: https://stackoverflow.com/questions/563 ... aring-brow