'How to change window selenium java?

I'm trying to access iframe inside html tag.xpath is not working.How to change my window to iframe in selenium(java/maven)?



Solution 1:[1]

First you need to create driver object and after you can switch windows by id, name and WebElement.Then driver object has functions for switch back to default window.like this example.

// create driver object
WebDriver driver = DriverManager.getDriver();

// change window using iframe id or iframe name
driver.switchTo().frame("frame id or frame name");

// change window using WebElement object
driver.switchTo().frame(webElement);

Switch back window

// switch back to main frame
driver.switchTo().parentFrame();
// switch back one frame
driver.switchTo().defaultContent();

Content copy from (read this article) selenium window change article.Impotent information's here.

Solution 2:[2]

  1. Right Click on HTML Page the search there for iframe.
  2. Get the frame ID, Name or index.
  3. pass one of the above parameters into following command
    driver.switchTo.Frame(" ID or Name Or index");
    
  4. then try to use your xpath.

Solution 3:[3]

You can use: deiver.switchTo Method with the element locator, you can find more with the following: https://www.guru99.com/handling-iframes-selenium.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 waruna k
Solution 2 David Buck
Solution 3 Software Tester at ExpandCart