簡體   English   中英

如何使用 Selenium 在 Oracle OTBI 中定位 WebElement

[英]How to locate WebElement in Oracle OTBI using Selenium

我正在努力自動安排一些報告。 我已經打開報告,但 Selenium 找不到“齒輪”圖標。 下面是元素的 HTML:

<a id="reportViewMenu" title="Actions" class="imageButton1L" href="javascript:void(0)" role="menu" style="display: inline;"><span class="ariaLabel">Actions</span><img style="vertical-align:text-bottom;" src="/xmlpserver/static/v20220415.1218/theme/alta/images/toolbar/popupmenu_ena.png" alt="" border="0" onmouseover="this.src='/xmlpserver/static/v20220415.1218/theme/alta/images/toolbar/popupmenu_ovr.png'" onmouseout="this.src='/xmlpserver/static/v20220415.1218/theme/alta/images/toolbar/popupmenu_ena.png'" onmousedown="this.src='/xmlpserver/static/v20220415.1218/theme/alta/images/toolbar/popupmenu_dwn.png'"></a>

這是我使用 Java 定位元素的最新嘗試:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("'/html/body/table/tbody/tr/td/div/div/div/div/div[2]/div[1]/div/div[2]/a[2]'"))).click();

我嘗試過使用相對 xpath(使用帶有 ID、Title 和 Class 的屬性)、cssSelector 和 ID。 絕對堅持這一點,所以任何幫助將不勝感激。

所需元素是啟用JavaScript的動態元素。

要單擊元素而不是visibilityOfElementLocated() ,您需要為elementToBeClickable()引入WebDriverWait ,並且可以使用以下任一定位器策略

  • 使用cssSelector

     new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a#reportViewMenu[title='Actions'] span.ariaLabel +img"))).click();
  • 使用xpath

     new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@id='reportViewMenu' and @title='Actions']//span[@class='ariaLabel' and text()='Actions']//following::img[1]"))).click();

使用@undidected Selenium 的 xpath 和

driver.switchTo().frame(0);

我能夠找到元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM