簡體   English   中英

單擊鏈接硒后如何驅動瀏覽器窗口的新實例

[英]How to drive a new instance of a broswer window after clicking a link selenium

因此,我正在運行一個測試,該測試單擊一個鏈接,但是該鏈接會打開一個新的瀏覽窗口。 如何驅動硒中的新瀏覽器實例? 就像我可以使用一種特定的方法,還是可以創建一個新的硒對象來驅動該新的瀏覽器實例? 我會很感激一個例子

因此,一旦單擊鏈接,請執行以下操作:

//Get the parent window handle
String parentHandle = driver.getWindowHandle();

for(String handle : driver.getWindowHandles())
{
    driver.switchTo().window(handle);

    //Since window handles are random in order, verify whether you are on the correct page  
    if(driver.getTitle().equalsIgnoreCase(<Title of the new page>))
    {
         //do whatever you wish to do on this page
         //once done, you may need to close this page
          driver.close();
          break;
    }           
}
//Switch back to the parent page
driver.switchTo().window(parentHandle);

您可以使用窗口處理程序導航到新窗口,然后與新窗口中存在的元素進行交互。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM