久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 综合九九 | 精品国产欧美一区二区三区成人 | 在线观看毛片网站 | 久久久久久久久蜜桃 | 欧美成人黄色小说 | 国产精品精品久久久 | 插插宗合网 | 亚洲精品电影网在线观看 | 天天操网 | 黄网站涩免费蜜桃网站 | 在线不卡 | 久久久久国产一区二区三区不卡 | 视频在线一区二区 | 久久91| 亚洲国产成人精品女人久久久野战 | 久久av网 | 中文字幕一区二区三区日韩精品 | 日韩欧美在线播放 | 欧美一级久久精品 | 国产精品国产精品国产专区不片 | www.国产精品 | 欧美寡妇偷汉性猛交 | 欧美 日韩 视频 | 99re99| 超碰97av| 国产成人网 | 亚洲天堂一区 | 欧美色综合一区二区三区 | 一区二区三区成人 | 久久综合狠狠综合久久综合88 | 青娱乐av | 国产伦精品一区二区三区精品视频 | 日韩中出 | 亚洲精品福利在线 | 久久久久久久久久爱 | 久久青| h在线| 中文字幕第十一页 | 亚洲视频一区在线观看 | 天天夜干 | 97色在线视频 |