selenium跳轉新視窗的問題

2022-08-28 01:39:12 字數 1149 閱讀 7005

1、通過視窗的標題去跳轉新視窗

string parentwin=this.getwindowhandle();//

獲取當前視窗的控制代碼

setallwindowsid = driver.getwindowhandles();//

獲取所有視窗控制代碼

for(string windowid :allwindowsid)

}assert.assertequals("國雲資料市場", driver.gettitle());

system.out.println("new page title is:" + driver.gettitle());

2、通過tab的id,跳到最後乙個tab頁

setwinset = this.driver.getwindowhandles();//

獲取所有控制代碼

listwinlist = new arraylist(winset);//

轉成list列表

string newtab = winlist.get(winlist.size() - 2);//

定義新的tab頁是倒數第二個頁面

driver.close(); //

close the original tab 關閉最後乙個

driver.switchto().window(newtab); //

switch to new tab 跳到原來的倒數第二個

thread.sleep(1000);

另一種通過index的值去確定

setallwindowsid = driver.getwindowhandles();//

獲取所有視窗控制代碼

//listwinlist=new arraylist(allwindowsid);

driver.switchto().window(allwindowsid.toarray()[allwindowsid.size() - 1].tostring()); //跳到最後乙個tab頁

assert.assertequals("國雲資料市場", driver.gettitle());

system.out.println("new page title is:" + driver.gettitle());

selenium開啟新標籤頁而非新視窗

需求 用firefox瀏覽器開啟新頁面時,習慣點選瀏覽器頂部的加號開啟新標籤頁,而非開啟新視窗。多次測試,python通過selenium 模組開啟的都是新視窗,不滿足習慣,那麼該如何模擬此操作?解決 開啟該模組的配置檔案,配置檔案相對於python安裝目錄路徑為 python37 lib site...

QT 建立新視窗並且實現頁面跳轉

在我們建立好乙個專案的情況下,自動建立乙個介面,但是有的時候我們想要跳轉到另外乙個介面,這個時候就需要一種新技術,建立乙個新的介面,並且實現跳轉 目錄1 建立新的視窗 2 實現跳轉 當然還要實現跳轉,這個時候我們初步完成了新視窗類的建立。我們需要在你需要主動跳轉的視窗中去新增跳轉。我這裡是mainw...

標籤跳轉action並在新視窗中顯示返回頁面

使用struts2時,用超連結提交action,本來提交動作和設定表單寫在js裡,想要返回的頁面在新視窗中顯示,找了很多資料都沒有滿意的方法,最後還是通過html和js實現了這麼個效果,缺點是提交方式只能選擇get 因為是通過href提交的 有很多引數或者引數大時不好用。1 a target bla...