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

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

使用 Selenium 和 Java 13 自動化 Span

使用 Selenium 和 Java 13 自動化 Span

開滿天機 2023-08-16 17:37:02
我正在使用 Java 中的 selenium 自動化一個網(wǎng)站。<a id="pd-vote-button10359300" class="css-vote-button pds-vote-button"><span>Vote</span></a>對于這個按鈕,我需要在 Selenium 中自動單擊。我正在遵循但不工作。WebElement click = driver.findElement(By.id("pd-vote-button10359300"));JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", click);您能提出問題是什么嗎?后new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='css-vote-button pds-vote-button' and starts-with(@id, 'pd-vote-button')]/span[text()='Vote']"))).click();
查看完整描述

4 回答

?
www說

TA貢獻(xiàn)1775條經(jīng)驗 獲得超8個贊

click()在該元素上,您必須引發(fā)WebDriverWait?,并且elementToBeClickable()可以使用以下任一定位器策略:

  • cssSelector:

    new?WebDriverWait(driver,?20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.css-vote-button.pds-vote-button[id^='pd-vote-button']>span"))).click();
  • xpath:

    new?WebDriverWait(driver,?20).until(ExpectedConditions.elementToBeClickable(By.xpath("http://a[@class='css-vote-button?pds-vote-button'?and?starts-with(@id,?'pd-vote-button')]/span[text()='Vote']"))).click();

更新

作為替代方案,您可以使用executeScript()以下方法:

  • cssSelector:

    ((JavascriptExecutor)?driver).executeScript("arguments[0].click();",?new?WebDriverWait(driver,?20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.css-vote-button.pds-vote-button[id^='pd-vote-button']>span"))));
  • xpath:

    ((JavascriptExecutor)?driver).executeScript("arguments[0].click();",?new?WebDriverWait(driver,?20).until(ExpectedConditions.elementToBeClickable(By.xpath("http://a[@class='css-vote-button?pds-vote-button'?and?starts-with(@id,?'pd-vote-button')]/span[text()='Vote']"))));

查看完整回答
反對 回復(fù) 2023-08-16
?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗 獲得超13個贊

您收到ElementClickInterceptedException錯誤,這意味著頁面上的某些其他元素與您嘗試單擊的元素重疊。您需要以某種方式與頁面進(jìn)行交互,以使重疊元素不再重疊,或者使用 JavaScript 單擊該元素并觸發(fā)“單擊”事件。

許多網(wǎng)站都有與用戶一起滾動的頁面導(dǎo)航元素,因此諸如浮動導(dǎo)航標(biāo)題之類的內(nèi)容可能會阻礙您想要單擊的元素。DebanjanB 有一個很好的解決方案作為解決此問題的下一步,但我懷疑您在等待元素可單擊時會收到 TimeoutException。

您很可能需要觀看此自動化測試的執(zhí)行,然后在測試失敗后查看頁面,然后再發(fā)現(xiàn)如何解決此問題。


查看完整回答
反對 回復(fù) 2023-08-16
?
精慕HU

TA貢獻(xiàn)1845條經(jīng)驗 獲得超8個贊

為什么不執(zhí)行以下操作來單擊?

WebElement click = driver.findElement(By.id("pd-vote-button10359300"));
click.click()


查看完整回答
反對 回復(fù) 2023-08-16
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗 獲得超9個贊

可能您的 ID 正在更改。請嘗試以下 xpath。


//a[@class='css-vote-button pds-vote-button']/span[text()='Vote']

代碼:


WebElement click = driver.findElement(By.xpath("//a[@class='css-vote-button pds-vote-button']/span[text()='Vote']"));

JavascriptExecutor executor = (JavascriptExecutor) driver;

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


查看完整回答
反對 回復(fù) 2023-08-16
  • 4 回答
  • 0 關(guān)注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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