Click on button inside an iframe

Asked

Viewed 684 times

0

I’m using Selenium to test a page but the button I need to click is inside an iframe that is inside a frame.

this.wait.until(ExpectedConditions.elementToBeClickable(By.id("corpo")));
WebElement iframeCorpo = this.driver.findElement(By.id("corpo"));
WebDriver frame2 = this.frame.switchTo().frame(iframeCorpo);
frame2.findElement(By.id("btnQueryLivre")).click();

2 answers

0

you can map and already access the frame:

Private Webdriver driver;

@Before
public void setUp() throws Exception {
    System.setProperty("webdriver.chrome.driver", "/home/diamaral/Documentos/drivers/chromedriver");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("https://www.alura.com.br/");
}

@After
public void tearDown() throws Exception {
    driver.quit();
}

@Test
public void test() {
    new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.className("elasticMedia")));

}

0


I managed to click the button. I didn’t need to select the first frame, I switched it directly to the button frame and then clicked.

WebDriver frame2 = this.driver.switchTo().frame("corpo");
this.wait.until(ExpectedConditions.elementToBeClickable(By.id("btnQueryLivre")));
frame2.findElement(By.id("btnQueryLivre")).click();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.