Chrome和Firefox中的不同测试行为

问题描述

我有任务-为页面https://cloud.google.com/products/calculator编写测试

在Chrome测试中正常工作。在Firefox中,我收到异常NoSuchFrame。

driver.switchTo().frame(0);
driver.switchTo().frame("myFrame");
Webelement numberOfInstances = new WebDriverWait(driver,15)
                .until(ExpectedConditions.visibilityOf(element));
numberOfInstances.sendKeys("4");

我更正了该代码之后

driver.switchTo().frame(0);
new WebDriverWait(driver,10)
       .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("myFrame"));
Webelement numberOfInstances = new WebDriverWait(driver,15)
       .until(ExpectedConditions.visibilityOf(element));
numberOfInstances.sendKeys("4");

现在我得到另一个异常:TypeError:无法访问死对象

UPD: 可能会对任何人都有帮助。此错误是Firefox的典型错误,此处不是唯一的解决方案。当您尝试切换到框架时出现此问题。决定之一可能是运行递归方法,或者仅仅是Thread.sleep

public static void getToSomeFrame(WebDriver driver,String nameFrame) {
    try {
        if (countOfSwitchingInFrame < 10) {
            driver.switchTo().defaultContent();
            driver.switchTo().frame(0);
            new WebDriverWait(driver,10)
                    .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(nameFrame));
        }
        else {
            throw new Exception();
        }
    } catch (Exception e) {
        countOfSwitchingInFrame++;
        getToSomeFrame(driver,nameFrame);
    }

其中countOfSwitchingInFrame-尝试切换到框架的次数。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)