使用 Selenium Webdriver 单击超链接 [英] Click on hyperlink using Selenium Webdriver
问题描述
我在尝试使用 Selenium Webdriver 单击超链接时遇到问题.我尝试使用 CssSelector 以及 XPath,但似乎没有任何效果.我要做的就是点击 Google 文本.
<div class="test"><table class="first first-table"><tr><td class="第二张桌子"><a id="dummyID" href="https://www.google.com" target="_blank">Google</a></td></tr></tbody>`我试过 driver.FindElement(By.XPath("///*[@id='dummyID']")).Click();我还尝试使用 href 来查找链接...几乎所有内容.我一直收到无法定位元素"异常.有人有什么建议吗?
解决方案 试试这个:
driver.FindElement(By.LinkText("Google")).Click();
查看元素是否在框架或 iframe 内.如果是,您需要使用:
driver.SwitchTo().Frame("frameID");
I am having a problem while trying to click on a hyperlink using Selenium Webdriver. I tried using CssSelector as well as XPath and nothing seem to work. All I am trying to do is Click on the Google text.
<div class="hello">
<div class="test">
<table class="first first-table">
<tbody>
<tr>
<td class="second-table">
<a id="dummyID" href="https://www.google.com" target="_blank">Google</a>
</td>
</tr>
</tbody>
</table>`
I tried driver.FindElement(By.XPath("//*[@id='dummyID']")).Click(); I also tried using href to find the link...pretty much everything. All the time I am getting "unable to locate element" exception. Anyone has any suggestions?
解决方案 Try this:
driver.FindElement(By.LinkText("Google")).Click();
Look to see if the element is within a frame or iframe. If it is, you'll need to use:
driver.SwitchTo().Frame("frameID");
这篇关于使用 Selenium Webdriver 单击超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆