// 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 to main frame
driver.switchTo().parentFrame();
// switch back one frame
driver.switchTo().defaultContent();
1. get.windowhandle(): This method helps to get the window handle of the current window
2. get.windowhandles():This method helps to get the handles of all the windows opened. It stores all the current active windows into set..
so if you get all the window handle you can do is example:
code:
Set<String> setLink = driver.get.windowhandles();
now you can simply do the indexing and switch.
ex.
driver.get(setLink[2]);
3. Another method to switch is using keyBoardkeys
String clickl = Keys.chord(Keys.CONTROL,Keys.TAB);
String clickl = Keys.chord(Keys.CONTROL,Keys.(Index of window you like 1,2,3));
// open the link in new tab, Keys.Chord string passed to sendKeys
driver.findElement(
By.xpath("any xpath")).sendKeys(clickl);
4条答案
按热度按时间btqmn9zl1#
首先你需要创建一个driver对象,然后你可以通过id,name和WebElement来切换窗口。然后driver对象有切换回默认www.example.com的功能window.like。
切换后车窗
内容复制自(阅读本文)selenium window change article。此处为无效信息。
bsxbgnwa2#
1.右键单击HTML页面搜索iframe。
1.获取帧ID、名称或索引。
1.将上述参数之一传递到以下命令
中
1.然后尝试使用您的xpath。
mspsb9vt3#
您可以使用:
deiver.switchTo
方法与元素定位器一起使用,您可以通过以下方法找到更多内容:https://www.guru99.com/handling-iframes-selenium.html6mzjoqzu4#
基本上,问题是改变窗口,我们有java内置方法。