![](/img/trans.png)
[英]Selenium WebDriver C#: Exception Thrown Finding Element With SVG using XPath
[英]Selenium WebDriver C#: Exception thrown finding text input element
<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>
我在 Chrome 驱动程序中使用 XPath 来查找文本区域。 这是我的代码行。
ele = driver.FindElement(By.XPath("//div[@aria-autocomplete='list']"));
Chrome 驱动程序抛出 NoSuchElementException。 如何获取此元素以便向其发送文本?
要查找文本输入WebElement,您必须为所需的ElementToBeClickable()
引入WebDriverWait ,您可以使用以下任一定位器策略:
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...']")));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.