Reputation: 33
This is the HTML page I'm trying to locate the financial report. I have tried to use XPath, CSS selector but no luck:
<div id='cssmenu'>
<ul>
<!-- ANALYSIS -->
<div style="margin:10px">ANALYSIS</div>
<li class='has-sub'><a href='javascript:void(0)'><div>Accruals</div></a>
<ul>
<li><a href='/financial/dailyAccrualMaintain.do?action=DAILY_MAINTAIN_OPEN&clear=true'><div>Daily</div></a></li>
<li class='last'><a href='/financial/accrual.do?action=list1&clear=true'><div>Monthly</div></a></li>
</ul>
</li>
<li><a href='/financial/financialReports.do?action=LIST_REPORTS&clear=true'><div>Financial Reports</div></a></li>
<li><a href='/financial/validationReports.do?action=LIST_REPORTS&clear=true'><div>Validation Reports</div></a></li>
<li><a href='/financial/financialCheck.do?action=OPEN&clear=true'><div>Financial Check</div></a></li>
</ul>
</div>
Java code where I used CSS selector to locate the element and I also used wait untill element is visible:
private final String finacialReportpath = "div#cssmenu li:nth-child(3)";
@FindBy(css = finacialReportpath)
private WebElement finacialReport;
public void clickfinacialReport() {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(finacialReportpath)));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(finacialReportpath)));
this.finacialReport.click();
}
Upvotes: 1
Views: 64
Reputation: 1275
You can use this XPath:
//a[contains(.,'Financial Reports')]
and still, if you are not able to find it than make sure whether you are in any frame or not.
If present in the frame then switch to it and then try to find the element.
Upvotes: 1
Reputation: 1074038
It looks like you want to click the link, but you're selecting the li
instead. Perhaps select the link (which also has the advantage of having a fairly unique set of attributes):
private final String finacialReportpath = "a[href^='/financial/financialReports.do']";
// Changed -------------------------------^
@FindBy(css = finacialReportpath)
private WebElement finacialReport;
public void clickfinacialReport(){
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(finacialReportpath)));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(finacialReportpath)));
this.finacialReport.click();
}
^=
means "starts with".
Upvotes: 0