• 特殊窗体的切换处理:1.Iframe;2.浏览器多窗口;3.弹窗。


    1.Iframe切换定位处理。(处理无焦点问题)

    public void SwitchIframe() {
    driver.get("mkiframe");
    Actions MoseActions = new Actions(driver);
    WebElement IfameElement = driver.findElement(By.id("ueditor_0"));//定位到ifame框
    driver.switchTo().frame(IfameElement);//切换到ifame框
    WebElement Ueditor = driver.findElement(By.tagName("p"));//在iframe标签下根据标签名(p)定位到输入框
    MoseActions.moveToElement(Ueditor).click().sendKeys("我是萨比---哈哈哈").perform();//鼠标移动到输入框上点击并进行输入
    }

    2.浏览器多窗口的切换。

    public void WindowsHandle() {
    driver.get("mklogin");
    WebElement LoginElement = driver.findElement(By.id("js-sigin-btn"));
    Actions MoseActions = new Actions(driver);
    MoseActions.click(LoginElement).perform();
    java.util.List<WebElement> MenElementList = driver.findElements(By.className("item"));
    WebElement MobileElement = MenElementList.get(1);
    MoseActions.moveToElement(MobileElement).perform();
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Set<String> Handles = driver.getWindowHandles();//获取到当前的所有窗口
    String CurlHandle = driver.getWindowHandle();//获取到当前这个窗口
    for(String s : Handles) {
    if(s.equals(CurlHandle)) {//判断如果是当前窗口就提交
    continue;
    }else {//否则就继续切换
    driver.switchTo().window(s);
    }
    }
    driver.findElement(By.className("shizan-name")).click();//切换到当前窗口后定位并点击
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    driver.close();
    }

    3.弹窗的处理。(三类弹窗)

    public void AlertWindows() {
    driver.get("tanchuang");
    // 1.根据id定位到弹窗并点击2.切换到弹窗并点击确认按钮。(提示信息【成功或失败】类型的弹窗)
    driver.findElement(By.id("alert")).click();
    driver.switchTo().alert().accept();
    // 1.根据id定位到弹窗并点击2.切换到弹窗并点击取消按钮。3.切换到弹窗并点击确认按钮。(提示语【再次确认,是/否】类型的弹窗)
    driver.findElement(By.id("sure")).click();
    driver.switchTo().alert().dismiss();
    driver.navigate().refresh();//刷新当前页面
    driver.switchTo().alert().accept();
    // 1.根据id定位到弹窗并点击2.切换到弹窗并在输入信息。3.输入完成后点击确认按钮。(可以进行信息输入类型的弹窗)
    driver.findElement(By.id("three")).click();
    driver.switchTo().alert().sendKeys("我四大撒比");
    driver.switchTo().alert().accept();
    }

  • 相关阅读:
    linux设置永久别名
    网站架构
    c#: 判断Firefox是否安装
    似是故人来
    Python: re.sub()第二个参数
    Python: AES加密与解密
    c#: Noto Sans字体如何支持韩文
    Inno Setup安装程序单例运行
    朵朵的二维码
    Python: 浅淡Python中的属性(property)
  • 原文地址:https://www.cnblogs.com/wangffeng293/p/13834430.html
Copyright © 2020-2023  润新知