0

I want to click 4th list element which is expanded in below html code.

The xpath is every time same as //*[@id='filter_result_totals']/ul/li[4]/a

The element value 1946 is always changing, it's representing as count of records.

<document>
<html>
<head>
<body style="overflow-y: hidden;">
<div class="container">
<div id="header" class="header">
<div class="main-menu menu menu-left">
<div class="headercontent">
<div style="display: none">
<div class="finder">
<div id="profile" class="profile menu">
<div class="clear"/>
<div class="main-toolbar">
<div class="main-toolbar-title">List view</div>
<div class="main-toolbar-subtitle">
<div class="main-toolbar-info">
<div id="filter_result_totals">
<ul>
<li class="extra_toolbar_category">
<li>
<li>
<li>
<a class="query_link" href="/monitor/index.php/listview?q=%5Bservices%5D%20state!%3D0%20and%20acknowledged%3D0%20and%20scheduled_downtime_depth%3D0%20and%20host.scheduled_downtime_depth%3D0%20and%20state%3D2%20and%20has_been_checked%3D1" data-query="[services] state!=0 and acknowledged=0 and scheduled_downtime_depth=0 and host.scheduled_downtime_depth=0 and state=2 and has_been_checked=1" title="Services critical">
<span class="icon-16 x16-shield-critical" title="Services critical"/>
1946
</a>
</li>
<li>
<li>
</ul>
</div>
</div>
<div class="main-toolbar-buttons toolbar-buttons">
<div class="clear"/>
</div>
</div>
<div id="page_settings" class="page_settings">
<div id="content" class="content " tabindex="0" style="height: 605px;">
<div class="jq-notify-zone"/>
<script type="text/javascript">$.notify.sessionid = '9723b1738ffd58a3a48627f3f4a39e6bad230cd2';$.notify.configured = {};</script>
</div>
<ul id="property_menu" class="contextMenu">
<ul id="svc_property_menu" class="contextMenu">
<div id="fancybox-tmp"/>
<div id="fancybox-loading">
<div id="fancybox-overlay"/>
<div id="fancybox-wrap">
<div id="cboxOverlay" style="display: none;"/>
<div id="colorbox" class="" style="display: none;">
<div id="AutocompleteContainter_1485854680035" style="position: absolute; z-index: 99999; top: 36.7667px; left: 1353.13px;">
</body>
</html>
</document>

Can anyone help me on this issue?

13
  • Any Error you getting ? Commented Jan 31, 2017 at 9:36
  • Hi Narendra.. thanks for your response. yes am getting 'no such element: Unable to locate element' always. i have tried with xpath and also absolute path. a2.findElement(By.xpath("html/body/div[1]/div[1]/div[2]/ul/li[3]/a")).click();a2.findElement(By.xpath("//*[@id='filter_result_totals']/ul/li[4]/a")).click(); Commented Jan 31, 2017 at 9:47
  • can you try this ` WebElement element = driver.findElement(By.xpath("//*[@id='filter_result_totals']/ul/li[4]/a")); JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("arguments[0].click();", element);` Commented Jan 31, 2017 at 9:51
  • yeah...i have tried am getting below error.invalid selector: Unable to locate an element with the xpath expression //*[@id='filter_result_totals']‌​/ul/li[4]/a because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[@id='filter_result_totals']‌​/ul/li[4]/a' is not a valid XPath expression. Commented Jan 31, 2017 at 9:57
  • How about link title: is "Services critical" unique value? Commented Jan 31, 2017 at 10:11

2 Answers 2

1

It might be timing issue. Try to set implicit wait

a2.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Or use explicit wait

WebDriverWait wait = new WebDriverWait(a2, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='filter_result_totals']/ul/li[4]/a")));
element.click();

See waits

Sign up to request clarification or add additional context in comments.

2 Comments

Hi. thanks for your response. its not working. because for every li element class name is 'query_link'.
@JegaB Edited my answer.
0

You may try with the following:

driver.findElement(By.cssSelector("a[class='query_link'][title='Services critical']")).click();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.