simonshout simonshout - 1 year ago 92
CSS Question

I need help finding a web element in selenium Java

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(""));

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.

xyz xyz
Answer Source

You can try to find element by its placeholder

driver.findElement(By.xpath("//input[@placeholder='Ask me anything!']"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download