2014-02-06 102 views
0

单击提交按钮后,会在现有窗口上打开新页面。在这个新窗口中,有一个链接。你将如何使用WebDriver来点击这个链接?当我右键单击链接文本和检查与萤火虫元素,我得到以下内容:单击提交按钮后如何点击链接

<a id="ctl100_ContentPlaceHolder1" class="prev-next previousYear" href="Enrollment2013.aspx?4fd70df97f0748ea82e787e5cf5b8552"><<previous year</a> 

谢谢。

+0

什么它混淆了你?这是一个像其他一切的元素。你现在正在查找使用定位器的特定元素,是吗?那么这有什么不同呢? – Arran

回答

0

的Java:

driver.findElement(By.id("ctl100_ContentPlaceHolder1")).click(); 

的Python:

driver.find_element_by_id("ctl100_ContentPlaceHolder1").click(); 
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. 

我相信这将帮助你:)