I am trying to click on a "Verify Now" button which is nested inside the tag and . I cannot directly navigate to href link since, each link every time has a different token to activate and which is why I am proceeding to rather click on it.
<a href="http://click1.clickrouter.com/redirect?token=a2258079c24c4c50a56b6b1ffb75d6e2&url=https%3A//sequoia-api-staging-write.ymedia.in/write/api/v1/contact/activate_account%3FtempSignupToken%3D9190c8f7-70e7-4b4f-a915-2d4498eb7c32" style="text-decoration: none ; color: white" target="_other" rel="nofollow">Verify Now</a>
有人可以帮我提供代码吗?我尝试过以下代码,但仍然没有帮助。不确定,丢失了什么。
@Selenium_driver.find_element(:xpath, "//button[contains(text(), 'Verify Now')]")
@Selenium_driver.find_element(:css, ".Verify.Now").click
@Selenium_driver.find_element(:link_text, "Verify Now").click
此外,iframe中该电子邮件正文的页面来源如下:
<div class="col-lg-12 col-md-12 col-sm-12" style="height:800px;clear:both;margin-bottom: 20px;padding-bottom: 20px;">
<iframe id="publicshowmaildivcontent" width="100%" height="100%" style="border: 0;">
EMAIL BODY
</iframe>
</div>
答案 0 :(得分:0)
您可以在案例中使用以下xpath:
driver.findElement(By.xpath("//*[contains(text(),'Verify Now')]")).click();
希望它会对你有所帮助。
答案 1 :(得分:0)
修改了答案:
@Selenium_driver.switch_to.frame("publicshowmaildivcontent")
@Selenium_driver.find_element(:xpath, "//a[contains(text(), 'Verify Now')]").click
或者你可以这样做:
@Selenium_driver.switch_to.frame("publicshowmaildivcontent")
@Selenium_driver.find_element(:xpath, "//a[contains(@href, 'http://click1.clickrouter.com/')]").click
//尝试点击javascript:
@Selenium_driver.switch_to.frame("publicshowmaildivcontent")
@element = @Selenium_driver.find_element(:xpath, "//a[contains(@href, 'http://click1.clickrouter.com/')]");
@Selenium_driver.executeScript("arguments[0].click();",@element);