-1

I am working with Selenium Web driver and need to reference am item in a javascript menu that has no id. I need to know how I can get the following web element in Selenium. I am not very proficient with javascript or HTML so any help is needed.

<td class="menu" colspan="2">
    <a href="javascript:Redirect('marks',0);" class="menu">
        Display Text Here
    </a>
</td>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

You can locate this element by xPath:

//a[contains(., 'Display Text Here')]

so in JavaScript it will be like this:

driver.findElement(By.xpath("//a[contains(., 'Display Text Here')]")).click();

Here you will find more information.

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
0

To get the element with text as Display Text Here you can use either of the following Locator Strategies:

  • LinkText:

    "Display Text Here"
    
  • CssSelector:

    "td.menu>a.menu"
    
  • XPath:

    "//td[@class='menu']/a[@class='menu'][contains(.,'Display Text Here')]"
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You can use this linkText :

Note that you should always choose linkText when compared to xpath and cssSelector.

driver.findElement(By.linkText("Display Text Here")).click();
cruisepandey
  • 28,520
  • 6
  • 20
  • 38