我有像下面的html页面,我需要点击clslogin类中的Login. 如何遍历以查找登录. 我正在使用C#和selenium Webdriver. 使用XPath(/ html / body / div / table / tbody / tr [1] / td [3] / a)我没有控制Login类,总是找不
如何遍历以查找登录.
我正在使用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的元素,您必须两次引导WebDriverwait来切换2子帧,然后再次找到所需的元素,如下所示:
//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();
注意:您不必考虑是否存在< frameset>并且可以安全地忽略这些标签.
