代码之家  ›  专栏  ›  技术社区  ›  Vinod Guneja

如何使用selenium RC和Java处理弹出窗口

  •  0
  • Vinod Guneja  · 技术社区  · 11 年前

    我试图自动化电子商务网站&我有一个问题,如何处理弹出窗口。请看一下场景。

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

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

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

    我在第3点卡住了,错误出现了,没有找到元素。

    这是我写的东西。

    @测试 public void 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"));
    

    }

    1 回复  |  直到 11 年前
        1
  •  0
  •   Sumitbit2005    11 年前

    使用以下代码: 我认为在步骤2之后应该有wait命令,我已经编辑了步骤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"));