如何使用 Selenium RC 与 Java 处理弹出窗口



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

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

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

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

我卡在第 3 点上,错误是找不到元素。

这是我写的东西。

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

}

使用以下代码:我认为在步骤 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"));

最新更新