0

Here is the HTML:

<input id="ember354" class="ember-view ember-text-field search" placeholder="Ask me anything!" type="text">

Which is reached from body-div-div-input

  • I can't find the element by tag due to there being more than 1 input tag
  • I can't find the element by id due to it being dynamic
  • I can't find the element by class due to compound class name
  • I've tried many different CSS selectors with no success
  • I've tried many different XPATH lines with no success

Different variations of this code replacing * with input and using contains & starts-with functions were of no use:

WebElement ele = driver.findElement(By.xpath("//*[@class='ember-view ember-text-field search']"));

Different CSS selectors like this were used including contains and other functions were of no success either

WebElement ele = driver.findElement(By.cssSelector("ember-view.ember-text-field.search"));

I thought maybe searching by placeholder since that is static would be a good idea but I do not know how to go about that.

7
  • Both queries should work. What is the method returning? Commented Apr 22, 2014 at 18:55
  • Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element Commented Apr 22, 2014 at 18:58
  • 1
    Does the page create that element dynamically? Commented Apr 22, 2014 at 19:00
  • Is this element inside an iframe. Commented Apr 22, 2014 at 19:00
  • No, the full path is literally //body/div/div/input Commented Apr 22, 2014 at 19:08

2 Answers 2

4

You can try to find element by its placeholder

driver.findElement(By.xpath("//input[@placeholder='Ask me anything!']"))
Sign up to request clarification or add additional context in comments.

Comments

0

You are making mistake with css selector. I think you forgot to put . in front of class name while using css selector.

Correct css locator would be .ember-view.ember-text-field.search

So your final code look like :

String cssLocator = ".ember-view.ember-text-field.search";
WebElement ele= driver.findElement(By.cssSelector(cssLocator));

or if you want to make it more specific then you can use:

String cssLocator = ".ember-view[placeholder='Ask me anything!']"; also

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.