首页 > 解决方案 > 在 IE 上测试时无法单击元素

问题描述

下面的代码在 chrome 中运行良好,能够切换到框架并单击注销按钮。但是在 IE 的情况下,它显示“无法单击元素错误”。而不是(.click())我使用(.submit())然后它会给出错误,如“执行 javascript 时出错”。

         driver.switchTo().frame("brandingTop");
         driver.findElement(By.xpath("//a[contains(.,'Logout')]")).click();

<html>
<head><title>Software Testing Help - iframe session</title>
</head>
<body>
  <frameset id="frRoot" framespacing="0" border="0" frameborder="0" rows="125,26,*,0,0">
        <frameset id="frRoot" framespacing="0" border="0" frameborder="0" rows="125,26,*,0,0">
    <frame id="frTopLeftPane" scrolling="no" name="brandingTop" src="/BIW/Lobby/Frameset/BrandingTop.aspx?dv=1&amp;nfGuid=">
    <a style="vertical-align:top;" href="/ic/bin/logout.asp?sessionid=&amp;id=338206" target="_top">
                                <img src="/skins/BIW/NewSkin/images/logout.gif" alt=""> Logout
                            </a>
                            </frame>

    </frameset>
    </frameset>

</frameset>
</body>

 System.setProperty("webdriver.ie.driver",AbsoluteDriverPath); 
 webdriver=new InternetExplorerDriver();
 webdriver.get(URL);
 webdriver.manage().window().maximize();
 webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

         driver.switchTo().frame("brandingTop");
         driver.findElement(By.xpath("//a[contains(.,'Logout')]")).click();

标签: javaseleniumtestng

解决方案


尝试使用框架元素本身而不是名称来切换框架。

frameElement = driver.findElement(By.xpath("//frame[contains(@name,'brandingTop')]"));
driver.switchTo().frame(frameElement);

推荐阅读