0
<div class="col-lg-3 col-sm-4 col-xs-6">
<div class="logo">..................</div> </div>

logo is inner div.

I need to acces col-lg-3 col... div content using xpath.

I did this in java: WebElement mydiv = driver.findElement(By.className("col-lg-3 ")) ; but it does not work - because it has spaces in the name.

How do I access this using xpath?

2 Answers 2

1

In CSS, you could access it like this:

driver.findElement(By.cssSelector(".col-lg-3 .logo"));

Since you asked, in XPath, it could be:

driver.findElement(By.xpath("//div[contains(@class, 'col-lg-3')]/div[contains(@class, 'logo')]")

As you can see, the CSS selector is much simpler.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry my first div class name is this: col-lg-3 col-sm-4 col-xs-6, it has spaces already! selecting with css does not work
the . selector in CSS doesn't care about spaces. you can take a look at this blog post which would explain a little bit better on how CSS can work for you.
0

To see xpath, I suggest to install Firebug and FirePath; those extensions are Firefox.

Example: Can you see the image? xpath

Imagine that you don't have id neither name locators or you need to use xpath

  1. Open Firefox.
  2. Click on "Firebug". (#1)
  3. There a panel.
  4. Click on "Click an element in the page to inspect" icon (#2)
  5. Click on "FirePath" tab. (#3)
  6. Select the element that you wish (#4)
  7. It displays the xpath into textbox. (#5)

So, you need to add this line:

driver.findElement(By.xpath("html/body/form/fieldset/p[1]/input"));

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.