我试图自动化电子商务网站&我有一个问题如何处理弹出窗口。请看一下场景。
转到http://www.angara.com/p/pear-tanzanite-and-diamond-v-bale-pendant-sp0169t.html
在产品页面上点击“添加到购物车”按钮(这会将产品添加到购物车并显示弹出窗口)
在弹出窗口中,我想点击结帐按钮(这会关闭弹出窗口)
我坚持第3点,错误是找不到元素。
这是我写的东西。
@Test 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"));
}
答案 0 :(得分:0)
使用以下代码: 我认为在第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"));