请帮忙,我是Selenium的新人.我尝试自动化电子商务网站,我有问题处理弹出窗口.这是场景:
我坚持第5步(错误信息:无法找到元素"继续购物按钮")这是我在第5步之前的代码:
WebDriver d1 = new FirefoxDriver();
d1.manage().window().maximize();
d1.get("http://www.lampsplus.com");
d1.findElement(By.name("hdr_sale")).click();
d1.findElement(By.xpath(".//*[@id='sortResultContainer60238']/a[2]/span")).click();
d1.findElement(By.id("pdAddToCart")).click(); //This is step 4
//Here is suppose to be some code which handles the popup - my problem
d1.findElement(By.id("aContinueShopping")).click(); //This is step 5
Run Code Online (Sandbox Code Playgroud)
我知道.getWindowHandle(); 方法.我尝试了几种不同的方法,但都没有.任何人都可以给我一个如何处理它的想法.非常感谢!我用的是Java.
注意:我不为LampsPlus工作而不尝试推广他们的产品,本网站仅用于培训目的.
该元素aContinueShopping包含在iframe中.
你必须使用以下方法切换到iframe:
WebElement frameID = d1.findElement(By.Css("#add-to-cart>iframe"));
d1.SwitchTo().Frame(frameID);
d1.findElement(By.id("aContinueShopping")).click();
Run Code Online (Sandbox Code Playgroud)
iframe上没有'name'或'id',因此您必须使用WebElement或数字来查找它.
完成iframe后,您将使用以下命令切换回"top":
d1.SwitchTo().DefaultContent();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18540 次 |
| 最近记录: |