第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

讓 selenium 等待 - WebDriverWait 問題

讓 selenium 等待 - WebDriverWait 問題

一只斗牛犬 2023-07-28 15:28:48
我面臨著無法解決的硒問題。我收到以下錯誤”no such element: Unable to locate element:{"method":"id","selector":"menu-supply-approval-queue"} 我知道問題在于等待。所以我做了下一個方法:public static WebElement getWebElementByIdWithWait(String id)    {        WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));        return WebDriverMgr.waitForElementToBeClickable(By.id(id));    }然而,selenium 不會等待,并再次出現(xiàn)此錯誤:Thu Sep 12 16:56:45 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"menu-supply-approval-queue"}  (Session info: chrome=76.0.3809.132)  (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 0 millisecondsFor documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.htmlBuild info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'System info: host: '', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'Driver info: org.openqa.selenium.chrome.ChromeDriver有人可以建議如何讓硒等待元素顯示/可點擊嗎?它一刻也不等更奇怪的是,selenium 實際上返回了該元素,然后單擊它,所以如果他找不到它,他如何返回它?它只會弄亂日志這是有效的代碼,但它使用睡眠 public static WebElement getWebElementByIdWithWait(String id)    {        Logger.sleep(60000);      //  WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 8);     //   wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));        return WebDriverMgr.waitForElementToBeClickable(By.id(id));    }問候
查看完整描述

4 回答

?
守著星空守著你

TA貢獻1799條經(jīng)驗 獲得超8個贊

這個錯誤信息...


Thu Sep 12 16:56:45 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"menu-supply-approval-queue"}

? (Session info: chrome=76.0.3809.132)

? (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 0 milliseconds

For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

System info: host: '', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'

Driver info: org.openqa.selenium.chrome.ChromeDriver

..意味著ChromeDriver無法啟動/生成新的WebBrowser(即Chrome 瀏覽器會話)。

您的主要問題是您使用的二進制文件版本之間不兼容,如下所示:

  • 您正在使用chromedriver=2.36

  • chromedriver=2.36的發(fā)行說明明確提到了以下內(nèi)容:

支持Chrome v63-65

  • 您正在使用chrome=76.0

  • ChromeDriver v76.0的發(fā)行說明明確提到了以下內(nèi)容:

支持Chrome 版本 76

  • 您的JDK 版本1.8.0_65,這是相當古老的。

因此JDK v8u65、ChromeDriver v2.36Chrome 瀏覽器 v76.0之間存在明顯的不匹配


解決方案

確保這件事:

  • JDK已升級到當前級別JDK 8u222。

  • ChromeDriver已更新至當前ChromeDriver v77.0級別。

  • Chrome已更新至當前Chrome 版本 77.0級別。(根據(jù)ChromeDriver v77.0 發(fā)行說明)

  • @Test非 root用戶身份執(zhí)行。


查看完整回答
反對 回復 2023-07-28
?
米脂

TA貢獻1836條經(jīng)驗 獲得超3個贊

您發(fā)布的方法有一個 id 的字符串參數(shù),但您在第二行中硬編碼等待特定 ID


public static WebElement getWebElementByIdWithWait(String id)

{

    WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("menu-supply-approval-queue")));

                                                             ^ this is hardcoded


    return WebDriverMgr.waitForElementToBeClickable(By.id(id));

}

您是否嘗試過刪除該行?


public static WebElement getWebElementByIdWithWait(String id)

{

    WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 300000000);

    return wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(id));

}

如果是我的話,我會使用下面的方法。它并不特定于 ID(您傳入 a By,因此它可以與 ID、CSS 選擇器、XPath 等一起使用),并且它會為您處理點擊,因此等待是特定于可點擊的。


public static void click(By locator)

{

    new WebDriverWait(WebDriverMgr.getDriver(), 15).until(ExpectedConditions.elementToBeClickable(locator)).click();

}

你會這樣稱呼它


click(By.id("menu-supply-approval-queue"));


查看完整回答
反對 回復 2023-07-28
?
冉冉說

TA貢獻1877條經(jīng)驗 獲得超1個贊

存在預期條件 elementToBeClickable

WebDriverWait wait = new WebDriverWait(WebDriverMgr.getDriver(), 60);
        wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-supply-approval-queue")));

我不確定 waitForElementToBeClickable 調(diào)用在哪里/做什么以及為什么它可能會失敗。


查看完整回答
反對 回復 2023-07-28
?
慕哥6287543

TA貢獻1831條經(jīng)驗 獲得超10個贊

也許你可以嘗試“Thread.Sleep(1000);” 喜歡



查看完整回答
反對 回復 2023-07-28
  • 4 回答
  • 0 關(guān)注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號