0

I am new to Selenium and XPath. Can you please help me I identified the XPath correctly for the following structure:

<body>
<div id="body-wrapper">
<div id="outer-wrapper">
<div id="wrap2">
<div class="span-24">
<div style="clear: both;"/>
<div id="header-wrapper">
<div style="clear: both;"/>
<div class="span-24">
<div class="menu-secondary-container">
<ul class="menus menu-secondary">
<li>
<li>
<li class="">
<a class="sf-with-ul" href="#">
Automation
<span class="sf-sub-indicator">»</span>
<span class="sf-sub-indicator">»</span>
</a>
<ul class="children sub-menu" style="display: none; visibility: hidden;">
<li>
<a href="http://www.ufthelp.com/p/uft.html" title="UFT">UFT</a>
</li>

I have identified the XPath as:

("//div[@class='menutext']/descendant::ul[@class='children sub-menu']/a[@href='http://www.ufthelp.com/p/uft.html']"));

But I'm running into NoSuchElementException. Please help me with the same. Thanks

Alon Adler
  • 3,984
  • 4
  • 32
  • 44
  • I feel this will help you to find them easily & learn http://stackoverflow.com/questions/3030487/is-there-a-way-to-get-the-xpath-in-google-chrome & FYI, the HTML you have given is not correct – Garfield Dec 29 '16 at 11:13
  • try this `//*[@id="header-wrapper"]/div/div/div/ul/li[3]/ul/li/a` – sandyJoshi Dec 29 '16 at 11:30

3 Answers3

0

U can get Xpath easily using firebug Extension in firofox browser . Just selecting by the the element u can get the xpath value . FirePath is a Firebug extension that adds a development tool to edit, inspect and generate XPath .

Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26
0
  1. the class "menutext" is missing.
  2. if your aim is to get a lock on the anchor tag, then I would suggest an alternate rather than xpath. Please try

`

driver.findElement(By.tagName("a")) then(function(anchorTags) {
  anchorTags.getText().then(function(anchorText) {
    if (anchorText == UFT) {
      // do your thing here
    }
  })
})

`

Rajkumar Somasundaram
  • 1,225
  • 2
  • 10
  • 20
0

XPATH :

//a[@title='UFT']

or

//a[text()='UFT']

CSS:

a[title='UFT']