久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Selenium 將焦點切換到選項卡,單擊鏈接后打開

Selenium switch focus to tab, which opened after clicking link(Selenium 將焦點切換到選項卡,單擊鏈接后打開)
本文介紹了Selenium 將焦點切換到選項卡,單擊鏈接后打開的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

出于自動化目的,我正在創建一個在表格中查找行的腳本.此行是可點擊的,并打開一個新的選項卡/地址.

For automation purposes, I am working on creating a script that finds a row in a table. This row is clickable and opens a new tab/adress.

使用 selenium,我現在可以找到表格行,單擊鏈接,然后打開新選項卡.問題是我找不到任何方法將焦點切換到新打開的選項卡.我試圖獲取所有 windowHandle 并查看是否可以切換,但即使在新選項卡打開后,也只有 1 個 windowHandle.

With selenium, I am now able to find the table row, click on the link, and the new tab opens. The problem is that I can't find any way to switch the focus to the newly opened tab. I tried to get all windowHandles and see if I could switch, but even after the new tab has opened, there is only 1 windowHandle.

下面是我的代碼:

WebElement tableRow=driver.findElement(By.xpath("/html/body/div[1]/table/tbody/tr[2]"));

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", tableRow);

ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
    for(String winHandle : driver.getWindowHandles()){
        driver.switchTo().window(winHandle);
    }

Arraylist 始終包含 1 個單個 windowHandle,而不是 2 個.所以我無法將焦點切換到新選項卡.有沒有辦法解決這個問題?

The Arraylist always contains 1 single windowHandle, not 2. So I am not able to switch focus to the new tab. Is there any way to solve this?

推薦答案

要正確切換到新打開的 Tab 你需要為 New 誘導 WebDriverWaitTab 進行渲染,然后通過 for() 循環,您需要遍歷可用的 WindowHandles 并調用 switchTo().window()WindowHandle 不是通過以下代碼塊的前一個 TAB :

To properly switch to the newly opened Tab you need to induce WebDriverWait for the New Tab to render and then through a for() loop you need to iterate through the available WindowHandles and invoke switchTo().window() with the WindowHandle which is not the previous TAB through the following code block :

String first_handle = driver.getWindowHandle();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", tableRow);
new WebDriverWait(driver,5).until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allHandles = driver.getWindowHandles();
for(String winHandle:allHandles)
{
    if (!first_handle.equalsIgnoreCase(winHandle)
    {
        driver.switchTo().window(winHandle);
    }
}

這篇關于Selenium 將焦點切換到選項卡,單擊鏈接后打開的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲福利一区二区 | 国产色在线| 欧美男人的天堂 | 精品在线99 | 青草福利 | 成人av一区二区亚洲精 | 日韩国产中文字幕 | 91精品国产91久久久久久 | 一级片av | а天堂中文最新一区二区三区 | 欧美激情国产日韩精品一区18 | 日韩视频在线播放 | 久久草在线视频 | 色偷偷噜噜噜亚洲男人 | 亚洲成人免费av | 成人一区二区在线 | xxxxx黄色片| 国产一区二区三区在线看 | 精品1区2区 | 中文在线一区二区 | av入口| 精品国产不卡一区二区三区 | 九色91视频| 中文字幕在线观看 | 欧美成人精品在线观看 | 亚洲精品一区中文字幕乱码 | 日韩成人免费 | 成人免费看片又大又黄 | 亚洲精品一区二区在线观看 | 成人永久免费 | 天天操天天插天天干 | 久久久久久国产精品免费免费狐狸 | 色视频网站 | 亚洲精品一区二区三区蜜桃久 | 国产一级一级国产 | 欧美日韩在线视频一区 | 一区二区三区日韩精品 | 成人在线视频观看 | 久久国产亚洲 | 成人国产精品久久 | 久久精品国产久精国产 |