单击提交按钮后,将在现有窗口上打开一个新页面。在这个新窗口中,有一个链接。您如何使用WebDriver点击此链接?当我右键单击链接文本并使用Firebug检查元素时,我得到以下内容:
<a id="ctl100_ContentPlaceHolder1" class="prev-next previousYear" href="Enrollment2013.aspx?4fd70df97f0748ea82e787e5cf5b8552"><<previous year</a>
谢谢。
答案 0 :(得分:0)
<强>爪哇:强>
driver.findElement(By.id("ctl100_ContentPlaceHolder1")).click();
<强>的Python:强>
driver.find_element_by_id("ctl100_ContentPlaceHolder1").click();
答案 1 :(得分:0)
在您描述的情况下,您必须切换到新窗口然后在那里操作。请看下面的代码:
String winHandle = driver.getWindowHandle(); //Gets your current window handle.
for(String windowsHandle : driver.getWindowHandles()){
driver.switchTo().window(windowsHandle); //Switch to new window.
}
driver.findElement(By.id("ctl100_ContentPlaceHolder1")).click(); //Click on the link in new window
driver.close(); //Close the new window after your operations are performed.
driver.switchTo().window(winHandle); //Switch back to original window.
我相信这应该对你有帮助:)。