Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:31:57+00:00 2026-06-18T00:31:57+00:00

Using selenium for the first time here, I was wondering why: final WebElement justAnId

  • 0

Using selenium for the first time here, I was wondering why:

final WebElement justAnId = findElement(By.cssSelector("#someId"));
final WebElement whatIWant = justAnId.findElement(
    By.cssSelector(".aClass.andAnother input[type=text]")
);

works, but not:

final WebElement whatIWant = findElement(By.cssSelector(
    "div#someId.aClass.andAnother input[type=text]"
));

Although they seem equivalent to me I get:

org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"css selector","selector":"div#someId.aClass.andAnother input[type=text]"}

Is this intended behaviour or a bug in Selenium? I had a quick look in the bug tracker in Selenium but I didn’t see anything about that. I wanted to ask here before raising an issue that doesn’t need to be. Also as far as I understand it doesn’t work in IE6 but who cares. I was using firefox for this run.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:31:58+00:00Added an answer on June 18, 2026 at 12:31 am

    findElement() finds an element in the current context, which means your first snippet of code is really finding an element that matches .aClass.andAnother input[type=text], which is contained within #someId. The element with that ID may or may not contain the two classes; WebDriver doesn’t assume you’re referring to the same element; it just finds the input as long as its ancestors are #someId and .aClass.andAnother.

    This is completely different from div#someId.aClass.andAnother input[type=text], which finds any input[type=text] within div#someId.aClass.andAnother only (i.e. it’s a div that contains both the ID and the classes).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time using PHPUnit and Selenium. Installed Selenium IDE plugin for Firefox, created some
I'm trying to get the first href attribute in a page using Selenium RC
First off, sorry for the cryptic question. My team is currently using Selenium 2.0rc3
I'm using Selenium 2/Webdriver with python and I want to click on the first
This is my first attempt at using Selenium, and I am having trouble with
I've run into a weird problem yesterday. I am using selenium-rc along with C#
At the moment i use selenium using HTMLSuite. The command i use to start
I am using selenium to test my webapp with chromedriver however selenium doesn't seem
I'm using Selenium to ease my testing burden and I have about 1,000 different
I'm using selenium-client to test a site. I want to get all a tags

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.