0
<div class="_5yk2" tabindex="-1"><div class="_5rp7"><div class="_1p1t" style=""><div class="_1p1v" id="placeholder-7mj5h" style="white-space: pre-wrap;">Write a post...</div></div><div class="_5rpb"><div aria-autocomplete="list" aria-controls="js_fe" aria-describedby="placeholder-7mj5h" aria-label="Write a post..." aria-multiline="true" class="notranslate _5rpu" contenteditable="true" role="textbox" spellcheck="true" style="outline: none; user-select: text; white-space: pre-wrap; overflow-wrap: break-word;"><div data-contents="true"><div class="" data-block="true" data-editor="7mj5h" data-offset-key="6o271-0-0"><div data-offset-key="6o271-0-0" class="_1mf _1mj"><span data-offset-key="6o271-0-0"><br data-text="true"></span></div></div></div></div></div></div></div>

I'm using XPath in the Chrome Driver to Find the Text Area. Here is my code line.

ele = driver.FindElement(By.XPath("//div[@aria-autocomplete='list']"));

The Chrome Driver throws an NoSuchElementException. How can I get this element so I can send text to it?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
GRF
  • 171
  • 2
  • 10

1 Answers1

0

To find the text input WebElement you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:

  • CssSelector:

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div[aria-autocomplete='list'][aria-describedby^='placeholder'][aria-label='Write a post...']")));
    
  • XPath:

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@aria-autocomplete='list' and starts-with(@aria-describedby, 'placeholder')][@aria-label='Write a post...']")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I had to install Selenium.Support to use ExpectedCondition and it compiles but is Deprecated. I discovered I can't use and starts-with(@aria-describedby, 'placeholder') because placeholder changes each time I run the code (i.e. placeholder-c0g2a). So the new code is `IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@aria-autocomplete='list'][@aria-label='Write a post...']")));` – GRF Sep 22 '20 at 14:31
  • But I still get the error **NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@aria-autocomplete='list'][@aria-label='Write a post...']"}** Please advise DebanjanB – GRF Sep 22 '20 at 14:31