Warm tip: This article is reproduced from stackoverflow.com, please click
iframe java selenium

Selenium cannot target div in iframe only on Chrome

发布于 2020-04-07 10:17:50

I have a div with a class attribute with the value textLayer. I'm trying to get that div. Here is my code:

WebElement jsiFrame = driver.findElement(By.tagName("iframe"));
        driver.switchTo().frame(jsiFrame);
        WebElement docViewerElement = driver.find(By.classname("textLayer")

(note: this isn't exactly the code but it's more or less the functions I call)

I also have a timeout where I wait 5 seconds while requesting each element so it's not a matter of the element not existing when I query it). Selenium fails to find it, even though it's very plainly there. What's more, it only fails on Chrome, Firefox finds it without any problems.

Questioner
Grumbunks
Viewed
47
Nagarjuna Yalamanchili 2020-02-01 09:11

Try dynamic xpath with explicit wait.