Contains expression in Selenium using Java Language

0 votes

I have used two paths :

 driver.findElement(By.xpath("//tr[@id='"+variable+"']/td[5]/span")).click();

 driver.findElement(By.xpath("//tr[@id='"+variable+"']/td[5]")).click();

How can I use both using contains expression so that the first or second version will be searched.

May 4, 2018 in Selenium by Martin
• 4,210 points
17 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Do something like this:

WebElement thingie = driver.findElement(By.xpath("//tr[contains(@id,'" + variable + "')]/td[5]"))
if (thingie.findElements(By.tagName("span")).size() != 0) {

    thingie.findElement(By.tagName("span")).click();

} else {

    thingie.click();

}

Make a starting point WebElement.

Check to see if the <span> exists. If so, click on the span version, otherwise, click the td directly.

answered May 4, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,209 views
0 votes
1 answer

How to scroll the Page up or down in Selenium WebDriver? (using java)

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
4,344 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
2,181 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
59 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
424 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
45 views
0 votes
1 answer

Identifying the page iframe in Selenium using Java Code

Open the page in a browser and ...READ MORE

answered May 24, 2018 in Selenium by Samarpit
• 5,130 points
39 views
0 votes
1 answer

Not able to login using selenium webdriver using Java Language

Try to send text to the username ...READ MORE

answered Jul 17, 2018 in Selenium by Samarpit
• 5,130 points
194 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.