0

enter image description hereIts name of tab. I have tried by Link-text but it's not working.

I have tried d.findElement(By.linkText("Clauses")).click(); It shows error

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"link text","selector":"Clauses"}

enter image description here

Bence Kaulics
1,00712 silver badges22 bronze badges
asked Jan 7, 2019 at 9:40
3
  • 1
    //span[contains(text(), 'Clause')], can you try this XPath please, Is there a chance the element to be in iFrame. Commented Jan 7, 2019 at 10:38
  • I think you need to consider the selector you are using. You have tried with class title which may be present in other parts of the DOM and so it may not work as expected. As suggested by others, try css or xpath selectors. You can try d.findElement(By.className("clauses")).click() to click on Clauses or d.findElement(By.className("myAssignedRequests")).click() to click on My Assigned Requests Commented Jan 7, 2019 at 11:04
  • Thank you all for your help! It worked .It was iframe. Commented Jan 8, 2019 at 8:58

3 Answers 3

1

Whole web page is frame. So first I switched to frame & then performed actions

d.switchTo().frame("frame-8_SNb34A224IASwxX0yc");
d.findElement(By.xpath("//[@id='tabviewMainContainerLexApp']/div/ul/li[11]/a/span")).click(); //click on tab using X-path
Bence Kaulics
1,00712 silver badges22 bronze badges
answered Jan 8, 2019 at 9:57
0

You can use byXpath to find element using xPath expressions. To get the link you should use the following:

//li[@class='uwa-tab clauses']/a[@href='#clauses']

To go further to get the span:

//li[@class='uwa-tab clauses']/a[@href='#clauses']/span[.='Clauses']

or a simplified one without the classes:

//li/a/span[.='Clauses']

If you want to find the link (<a>..</a>) and you want to filter only by the title you could use:

//li/a/span[.='Clauses']/..

This one locates the span by its text and then steps back to its parent by the /...

Also there are many more possibilities, this locator table cheat-sheat summarizes them quite well.

answered Jan 7, 2019 at 11:36
0
0

Why dont you simply select the anchor tag

driver.findElement(By.xpath("//a[contains(.,'Clauses')]")).click();
answered Jan 8, 2019 at 6:30
1
  • Thank you all for your help! It worked .It was iframe Commented Jan 8, 2019 at 8:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.