1

How to click on particular "add task" link , when more add tasks are there and I couldn't be able to find an unique Xpath

In this case the add task comes when we add new project, so every-time new add task generates.

3 Answers 3

3

From what I understand, you need to locate the "add tasks" link based on the project name. The project name node is not expanded on the screenshot, but I'm assuming there is an a element there too:

String projectName = "qrr";
driver.findElement(By.xpath("//tr/td[a = '" + projectName+ "']/following-sibling::td/a[. = 'add tasks']"));

This is to locate the "add tasks" button for the qrr project name.

Or, you can locate the appropriate row and use "by link text" locator:

WebElement row = driver.findElement(By.xpath("//tr[td/a = 'qrr']"));
WebElement addTasks = row.findElement(By.linkText("add tasks"));
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks for replying alecxe, Actually the condition is the "add task" link gets added with the same name i.e "add tasks" whenever we create new project so the linkText or the Xpath we cant use because it will not select the correct one , as all the project is having the same name for "add task"(refer screen shot). How to locate particular add task for different projects? .
The screenshot's resolution is too low. Could you provide us with a better one? Or maybe you could reproduce the HTML in your question.
@ChandanKumar I'm actually providing a way to locate the "add tasks" based on the project name. Isn't it what you are asking about?
@ThiagoPorciúncula - please zoom it for better view.
I believe @alecxe answered it.
|
0

You can use the Path but I will suggest to use the CSS Selector inlace of Path. CSS Selectors are faster than Path. To learn CSS Selector you can use http://www.w3schools.com/css/css_selectors.asp .

Comments

0

I used the following code and it worked perfectly fine

String ProjectName = "qrr";

driver.findElement(By.xpath("//tr/td/a[contains(text(),'"+ ProjectName +"')]/ancestor::tr[2]/td[2]/a[contains(text(),'add tasks')]")).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.