I am using Java and Selenium to write a test, I use the code below to get into Chrome:setting
driverChrome.manage().window().maximize();
driverChrome.get("chrome://settings");
But when the page is open I can not find any of its web Elements, for example when I try to find "show advanced setting...." by this code
driverChrome.findElement(By.xpath("//a[@id='advanced-settings-expander']")).click();
it throws an error saying that "no such element: Unable to locate element" I tried to located other elements, but they all failed. I saw this post here but it did not help.
Find the code below:
driverChrome.manage().window().maximize();
driverChrome.get("chrome://settings");
Thread.sleep(5000);
WebElement w = driverChrome.findElement(By
.xpath("//iframe[@name='settings']"));
driverChrome = driverChrome.switchTo().frame(w);
Thread.sleep(1000);
while (true) {
try {
WebElement we = w.findElement(By
.xpath("//a[text()='Show advanced settings...']"));
if (we.isDisplayed()) {
we.click();
Thread.sleep(1000);
break;
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("=========================");
}
}
I haven't tested this but I took your code snippet and cleaned it up a bit. Try this and see if it works. This should be pretty close.
Once you switch to the IFRAME context, you don't need to reference the
IFRAME
as you did withw.findElement()
.In general,
Thread.sleep()
is not a good practice. You should prefer to useWebDriverWait
withExpectedConditions
. Check the docs for all the different things you can wait for usingExpectedConditions
. I used.elementToBeClickable()
in my code below. This is perfect since you want to click an element. The.until()
returns the element waited for so you can just append.click()
on the end of the statement... or you can store the element in aWebElement
variable and use it elsewhere.