简体   繁体   English

如何在Selenium WebDriver中单击链接文本

[英]How to click link text in selenium webdriver

How to click the link text within an iframe? 如何在iframe中单击链接文本?

 <iframe id="PaymentFrame" src="http:///AccolentMVC/PaymentGW/payment?0JcINmGD1R3z/YV2fWT/YVRV8qXMPwXxer0Q634aBlT+KRL1LNdyEQtXL0MBOTXGTGdIM+NM/orGjrTKXS3tb5d5HG/6tUtND0JSdhGoAe1Ugk+kk81jR93x7u9aYYRdkluT3xDvNpoaKCaa0XMDmbJ1eFqMx7+7lw7PuFmXcXK5BO9NMUQspCPPIAPTmFJybBBHw4p2L+aHYTEA+FwZ0LTujo+wnhbQZL1qsoB9+xWSw/NOjHb/l+sfmmeMAcrO6SRl6/Rd2aY=" style="overflow:hidden;width:100%;height:475px" frameborder="0"></iframe> <html><head> <meta name="viewport" content="width=device-width"> <title></title> <aside> <fieldset id="navcontainer"> <legend><div style="color:#A20F00;font-size:18px;font-weight:bold">Payment Methods</div></legend> <div align="center" style="margin:10px;font-size:16;font-weight:bold;"> <p> Select payment method: </p> <ul> <li style="list-style-type:circle;width:80px;margin:10px;font-size:16;"><a href="/AccolentMVC/PaymentGW/UserData/1?key=Google%20Wallet&amp;key1=Google%20Wallet">Google Wallet</a></li> <li style="list-style-type:circle;width:80px;margin:10px;font-size:16;"><a href="/AccolentMVC/PaymentGW/UserData/1?key=gwAuthorizeNet&amp;key1=AuthorizeNet">AuthorizeNet</a></li> </ul> </div> </fieldset> </aside> </div> 

We are using this code and it doesn't click the Link text: 我们正在使用此代码,它不会单击“链接”文本:

    driver.switchTo().defaultContent(); 
    //driver.switchTo().frame(driver.findElement(By.id("PaymentFrame")));
    driver.findElement(By.linkText("Google Wallet")).click();   

Try using xPath. 尝试使用xPath。

Use below code to click on the link : 使用以下代码单击链接:

driver.switchTo().defaultContent(); 
driver.switchTo().frame(driver.findElement(By.id("PaymentFrame")));
driver.findElement(By.xpath("\\a[contains(text(),'Google Wallet')]");

'Google Wallet' is not present in iframe in the above html sample. 上述html示例中的iframe中不存在“ Google电子钱包”。 You can find it by using simple xpath like below. 您可以使用下面的简单xpath找到它。

driver.findElement(By.xpath("//a[text()='Google Wallet']");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Selenium Webdriver中单击具有相同名称的链接? - How to click link with same names in selenium webdriver? 如何通过Selenium Webdriver单击“隐藏”链接 - How to click on Hidden link through Selenium Webdriver selenium webdriver单击标记中的链接 - selenium webdriver click link in the tag 如何使用Selenium Webdriver 2.25-Java单击ahref链接? - How to click on the ahref link using selenium webdriver 2.25 - java? 如何<a class </a>在Selenium WebDriver中使用Java</a>单击带有标签名称的链接 - How to click a link with Tag name <a class </a> using Java in Selenium WebDriver 如何使用Selenium WebDriver(Java)单击图像/链接 - How to click on an image/link using Selenium WebDriver (Java) 如何使用Java中的Selenium WebDriver单击列表中的链接 - How to click the link located in a list using Selenium WebDriver in Java 如何通过 selenium-webdriver 在 url http://www.spicejet.com/ 上执行多个操作并单击带有文本的链接作为会员登录 - How to perform multiple actions and click on the link with text as Member Login on the url http://www.spicejet.com/ through selenium-webdriver 单击链接在Selenium Webdriver 2.45.0中不起作用 - Click link is not working in selenium webdriver 2.45.0 Selenium IE Webdriver无法单击“登录”链接 - Selenium IE webdriver is unable to click on the “Sign In” link
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM