selenium-无法找到登录名
我正在尝试将登录名定位到网页中,但无法执行相同的操作,因为元素不可见-获取NoTouchElement异常 我尝试使用下面的代码,但每次都出现异常。 WebDriverWait wait=新的WebDriverWait(驱动程序,30); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(“html/body/form/table/tbody/tr[3]/td[2]/input”)); driver.findElement(By.xpath(“html/body/form/table/tbody/tr[3]/td[2]/input”)).sendKeys(“admin”) 谁能帮我一下吗 感谢页面的HTML代码是:-selenium-无法找到登录名,selenium,Selenium,我正在尝试将登录名定位到网页中,但无法执行相同的操作,因为元素不可见-获取NoTouchElement异常 我尝试使用下面的代码,但每次都出现异常。 WebDriverWait wait=新的WebDriverWait(驱动程序,30); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(“html/body/form/table/tbody/tr[3]/td[2]/input”)); driver.f
<!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>
零售-J
很抱歉,您的浏览器不支持框架集。
这个问题有点模糊,因为您没有提供任何相关DOM的示例;但是,您可以首先验证所需元素在浏览器中是否实际可见。有时登录元素是隐藏的,仅在用户操作(如鼠标单击或鼠标悬停)时显示。
Selenium有两个函数,可以使元素可见(请参阅)。如果其他方法似乎都不起作用,则可以使用查找元素并将其返回以供使用,尽管这被视为一种不好的做法。NoTouchElement异常意味着您的定位器不正确。尝试以下事项:
让我知道它是否适合您。您没有指定项目使用的语言,因此我将用C#给出答案 我猜可能是web驱动程序执行速度太快,同时使用了错误的定位器,可能是登录页面多次使用相同的ID,这会使事情变得复杂 将以下等待添加到解决方案中,并查看是否有帮助:
Task.Delay(2000).Wait();
请在下面找到html代码:-页面源代码显示为您的元素位于框架内。请先在框架内切换(frame name=“contentFrame”),然后与输入字段交互。