首页 文章

selenium - 无法找到登录信息

提问于
浏览
-1

我试图找到登录到网页,但我不能做同样的元素是不可见的 - 获得Nosuchelement异常 .

我尝试使用下面的代码,但每次我得到例外 . WebDriverWait wait = new WebDriverWait(driver,30); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath( “HTML /体/形式/表/ tbody的/ TR [3] / TD [2] /输入”))); driver.findElement(By.xpath( “HTML /体/形式/表/ tbody的/ TR [3] / TD [2] /输入”))的SendKeys( “管理员”);

任何人都可以帮助我 .

感谢该页面的HTML代码: -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Retail-J</title>
    </head>


    <frameset name ="mainFrameset" id ="mainFrameset" rows="55,*" frameborder="1" framespacing="2" border="2" bordercolor="#000000">
        <frame name="titleFrame" src="title.jsp" marginheight="0" marginwidth="0" noresize="noresize" scrolling="no">
        <frameset name="innerFrameset" id="innerFrameset" cols="20.0%,*" frameborder="0" border="0" framespacing="0" >
            <frame name="contentFrame"  src="dynamicContents.jsp" marginheight="0" marginwidth="0" noresize="noresize" target="mainFrame" scrolling="auto">
            <frame name="mainFrame" src="Welcome.jsp" marginheight="0" marginwidth="0" scrolling="auto">
        </frameset>
        <noframes> 
            <body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0">
            Sorry your browser does not support framesets. 
             </body>
        </noframes> 
    </frameset>
</html>

3 回答

  • 0

    问题有点模糊,因为你没有提供相关DOM的任何例子;但是,您可以首先验证目标元素是否对浏览器实际可见 . 有时登录元素是隐藏的,仅在用户操作时出现(例如鼠标单击或鼠标悬停) . Selenium有几个函数可以让你呈现元素可见(参见here) . 如果似乎没有其他工作,你可以使用Javascript executor找到元素并将其返回使用,虽然这不是一个好习惯 .

  • 0

    NoSuchElement异常意味着您的定位器不正确 . 尝试下面的事情:

    • 尝试使用ID,NAME或XPATH查找元素 . 确保定位器是唯一的?

    • 检查元素是否在iframe /框架内?

    • 等待元素可见性 .

    请让我知道这对你有没有用 .

  • 0

    你没有指定你用于项目的语言,所以我只想用C#给出答案 .

    猜测我会认为它是Web驱动程序执行速度过快而且使用了错误的定位器的混合物,可能是一个多次使用相同ID的登录页面,这使得事情复杂化 .

    将以下等待添加到您的解决方案中,看看它是否有帮助:

    Task.Delay(2000).Wait();
    

相关问题