我有如下所示的 html 页面,我需要单击 clslogin 类中的“登录”。
如何遍历找到登录名。
我正在使用 C# 和 selenium Webdriver。
使用 XPath (/html/body/div/table/tbody/tr[1]/td[3]/a) 我无法控制 Login 类,总是抛出找不到元素的错误。任何人都可以帮助我获得准确的 xpath.
<html>
<head></head>
<frameset name="mytestTopFrame" rows="*"...... >
<frame name="mytestTopsubframe" src="index.html" width="100%"......... >
<html>
<head></head>
<frameset name="mytest" rows="70,20..."...... >
<frame name="mytestsubframe" src="menu.html" width="100%"......... >
<html>
<body class="clsmenu" .......>
<div align="left">
<table id="Title" ......>
<tbody>
<tr class="toptitle" ...>
<td class="clicklogin" ....>
<a class="clslogin" href="linkref">Login </a>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
</frame>
</frameset>
</html>
</frame>
</frameset>
</html>
根据HTML您已共享以单击文本为的元素Login你必须诱导WebDriver等待两次切换 2 个孩子frame
然后再次找到所需的元素,如下所示:
//SwitchTo mytestTopsubframe
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Name("mytestTopsubframe")));
//SwitchTo mytestsubframe
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Name("mytestsubframe")));
//Locate the desired element
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@class='clslogin' and @href='linkref']"))).Click();
Note: 你不必考虑的存在<frameset>
并且可以安全地忽略这些标签。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)