【问题标题】:How to handle popup window using selenium RC with Java如何使用带有 Java 的 selenium RC 处理弹出窗口
【发布时间】:2014-02-20 18:27:10
【问题描述】:

我正在尝试自动化电子商务网站,但我遇到了如何处理弹出窗口的问题。请看一下场景。

  1. 转到http://www.angara.com/p/pear-tanzanite-and-diamond-v-bale-pendant-sp0169t.html

  2. 在产品页面上单击“添加到购物车”按钮(这会将产品添加到购物车并显示一个弹出窗口)

  3. 在弹出窗口中我想点击结帐按钮(这将关闭弹出窗口)

我坚持第 3 点,错误是找不到元素。

这是我写的。

@测试 公共无效 angara_Home_product(){

 selenium.click("xpath=//span[contains(text(),'Tanzanite Pendant')]");
 selenium.waitForPageToLoad("30000");
 assertTrue(selenium.isTextPresent("Pear Tanzanite and Diamond V-Bale Pendant"));
 selenium.click("xpath=//img[@class='imgsize']/@src[1]");
 selenium.click("css=#option-list-tab272 > span");
 selenium.click("xpath=//div[@id='option-container3341']/div/div/span");
 selenium.click("css=#option-list-tab332 > span");
 selenium.click("xpath=//span[contains(text(),'14K Yellow Gold')]");
 selenium.click("//input[@name='addToCartSubmit' and @value='ADD TO CART']");

      //Some code should be there which might handle the pop-up window.

 selenium.click("xpath=//*[@id='cart-top-checkout-button']");
 selenium.waitForPageToLoad("30000");
 assertTrue(selenium.isTextPresent("Express Checkout"));

}

【问题讨论】:

    标签: java selenium selenium-rc


    【解决方案1】:

    使用以下代码: 我认为在第 2 步之后应该有等待命令,并且我已经为第 3 步编辑了 xpath。

    selenium.click("xpath=//span[contains(text(),'Tanzanite Pendant')]");
     selenium.waitForPageToLoad("30000");
     assertTrue(selenium.isTextPresent("Pear Tanzanite and Diamond V-Bale Pendant"));
     selenium.click("xpath=//img[@class='imgsize']/@src[1]");
     selenium.click("css=#option-list-tab272 > span");
     selenium.click("xpath=//div[@id='option-container3341']/div/div/span");
     selenium.click("css=#option-list-tab332 > span");
     selenium.click("xpath=//span[contains(text(),'14K Yellow Gold')]");
     selenium.click("//input[@name='addToCartSubmit' and @value='ADD TO CART']");
    selenium.waitForPageToLoad("10000");
    
          //Some code should be there which might handle the pop-up window.
    
     selenium.click("xpath=//form[@id='updatepost_form']//*[@id='cart-top-checkout-button']");
     selenium.waitForPageToLoad("30000");
     assertTrue(selenium.isTextPresent("Express Checkout"));
    

    【讨论】:

    • 使用您的代码时出现 10000 毫秒错误后超时。
    • 你可以使用Thread.sleep(10000);而不是 selenium.waitForPageToLoad("10000");试一试。
    • 你能告诉我你现在遇到了什么错误
    • Sumit,我已经使用了下面的代码,现在它正在工作。尝试{ Thread.sleep(10000); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); }
    猜你喜欢
    • 1970-01-01
    • 2017-01-08
    • 2013-10-24
    • 2013-02-03
    • 1970-01-01
    • 2015-07-09
    • 2021-01-11
    • 2015-06-29
    • 2017-04-28
    相关资源
    最近更新 更多