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

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

使用 Selenium Webdriver 單擊 JQUERY 元素時出現(xiàn)問題

使用 Selenium Webdriver 單擊 JQUERY 元素時出現(xiàn)問題

幕布斯6054654 2023-09-13 17:58:30
我正在嘗試從一個非常知名的網站單擊一些 JQUERY 元素來練習 Selenium(http://the-internet.herokuapp.com/jqueryui/menu)。我想出了如何導航到菜單(不確定我的代碼是否是一個好的解決方案),但是我無法單擊每個最后一個子菜單選項(PDF、CSV、Excel)我正在嘗試如下所示:Actions builder = new Actions(driver);Action mouseOverMenu;mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-2"))).build();mouseOverMenu.perform(); //accessing Enabled menu optionmouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-4"))).build();mouseOverMenu.perform(); //accessing Downloads submenu optionString jQuerySelector = "$('a#ui-id-6.ui-corner-all')";WebElement webElement = (WebElement) ((JavascriptExecutor) driver).executeScript("return $(" + jQuerySelector+ ").get(0);");//click() also did not workWebElement webElement = (WebElement) ((JavascriptExecutor) driver).executeScript("return $(" + jQuerySelector+ ").click();");
查看完整描述

1 回答

?
ITMISS

TA貢獻1871條經驗 獲得超8個贊

你的 JavaScript click 函數(shù)是錯誤的。


使用下面的 JavaScript 語法


executor.executeScript("arguments[0].click();", WebElement);

下面的代碼對我有用:


    Actions builder = new Actions(driver);

    Action mouseOverMenu;


    mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-2"))).build();

    mouseOverMenu.perform(); //accessing Enabled menu option


    WebDriverWait wait = new WebDriverWait(driver, 30);

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ui-id-4")));

    wait.until(ExpectedConditions.elementToBeClickable(By.id("ui-id-4")));


    mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-4"))).build();

    mouseOverMenu.perform(); //accessing Downloads submenu option


    WebElement webElement2= driver.findElement(By.cssSelector("a#ui-id-6.ui-corner-all")); // #ui-id-6 is for pdf, #ui-id-7 csv so on

    JavascriptExecutor executor = (JavascriptExecutor)driver;

    executor.executeScript("arguments[0].click();", webElement2);


查看完整回答
反對 回復 2023-09-13
  • 1 回答
  • 0 關注
  • 81 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號