Home > other >  How to locate WebElement in Oracle OTBI using Selenium
How to locate WebElement in Oracle OTBI using Selenium

Time:08-11

I'm working on automating the scheduling of some reports. I've gotten as far as opening the report, but Selenium can't locate the 'Gear' icon. Below is the HTML of the element:

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

Here is my latest attempt at locating the element using 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();

I've tried using relative xpath (using the attribute with ID, Title, and Class), cssSelector, and ID. Absolutely stuck on this so any help would be much appreciated.

CodePudding user response:

The desired element is a JavaScript enabled dynamic element.

To click on the element instead of visibilityOfElementLocated() you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • Using cssSelector:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a#reportViewMenu[title='Actions'] span.ariaLabel  img"))).click();
    
  • Using 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();
    

CodePudding user response:

Using @undidected Selenium's xpath and

driver.switchTo().frame(0);

I was able to locate the element

  • Related