Clicking button inside an iframe

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();
    
asked by anonymous 10.04.2018 / 21:06

2 answers

0

I was able to click the button. I did not have to select the first frame, I made the switch 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();
    
10.04.2018 / 21:46
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")));

}
    
15.04.2018 / 14:44