【问题标题】:Click on button with <href> and <a> tag单击带有 <href> 和 <a> 标记的按钮
【发布时间】:2017-11-14 18:52:07
【问题描述】:

我正在尝试单击嵌套在标签内的“立即验证”按钮和 .我不能直接导航到 href 链接,因为每个链接每次都有不同的令牌来激活,这就是为什么我继续点击它。

PFB html

<a href="http://click1.clickrouter.com/redirect?token=a2258079c24c4c50a56b6b1ffb75d6e2&amp;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>

【问题讨论】:

    标签: html ruby selenium safari automation


    【解决方案1】:

    您可以为您的案例使用以下 xpath:

    driver.findElement(By.xpath("//*[contains(text(),'Verify Now')]")).click();
    

    希望对你有帮助。

    【讨论】:

    • 有没有办法用部分href点击?
    【解决方案2】:

    修改答案:

    @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);
    

    【讨论】:

    • 检查.....使用第二个选项。你说的第一个也是@RNS建议的,没有用。 `@Selenium_driver.find_element(:xpath, "//a[contains(text(), 'Verify Now')]")
    • 你能检查你的元素是否在 iframe 中吗?
    • 我在检查器中没有看到任何带有文本
    • 嘿,我刚刚在 page_source 中看到,这个 EMAIL BODY 在 iframe 内。
    • &lt;div class="col-lg-12 col-md-12 col-sm-12" style="height:800px;clear:both;margin-bottom: 20px;padding-bottom: 20px;"&gt; &lt;iframe id="publicshowmaildivcontent" width="100%" height="100%" style="border: 0;"&gt; EMAIL BODY &lt;/iframe&gt;
    猜你喜欢
    • 2013-11-05
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-08
    相关资源
    最近更新 更多