Я пытаюсь ввести текст в div, тип которого textbox.
Перед вводом текста ознакомьтесь с фрагментом HTML-кода элемента:
<div class="_5yk2" tabindex="-1">
<div class="_5rp7">
<div class="_1p1t">
<div class="_1p1v" id="placeholder-fr28f" style="white-space: pre-
wrap;">Describe your item (optional)
</div>
</div>
<div class="_5rpb">
<div aria-autocomplete="list" aria-controls="js_1jt" aria-
describedby="placeholder-fr28f" aria-multiline="true" class="notranslate
_5rpu" data-testid="status-attachment-mentions-input" role="textbox"
spellcheck="true" style="outline: currentcolor none medium; -moz-user-
select: text; white-space: pre-wrap; overflow-wrap: break-word;"
contenteditable="true">
<div data-contents="true">
<div class="" data-block="true" data-editor="fr28f" data-offset-
key="496vr-0-0">
<div data-offset-key="496vr-0-0" class="_1mf _1mj">
<span data-offset-key="496vr-0-0">
<br data-text="true">
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
И после ввода текста он выглядит так:
<div class="_5yk2" tabindex="-1">
<div class="_5rp7">
<div class="_5rpb">
<div aria-autocomplete="list" aria-controls="js_1jt" aria-
describedby="placeholder-fr28f" aria-multiline="true" class="notranslate
_5rpu" data-testid="status-attachment-mentions-input" role="textbox"
spellcheck="true" style="outline: currentcolor none medium; -moz-user-
select: text; white-space: pre-wrap; overflow-wrap: break-word;"
contenteditable="true">
<div data-contents="true">
<div class="" data-block="true" data-editor="fr28f" data-offset-
key="496vr-0-0">
<div data-offset-key="496vr-0-0" class="_1mf _1mj">
<span data-offset-key="496vr-0-0">
<span data-text="true">abhinandan</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Итак, я попытался установить значения в соответствии с изменением HTML, используя innerHTML
, как показано ниже:
WebDriverWait waitForDiv= new WebDriverWait(driver,TimeSpan.FromSeconds(10));
var Ele = driver.FindElement(By.XPath("/html/body/div[6]/div[2]/div/div/div/div/div[2]/div/div/div[1]/div[5]/div[1]/div/div/div/div/div[2]/div/div/div/div"));
Ele.Click();
Thread.Sleep(2000);
IWebElement myElementRemoveDiv = driver.FindElement(By.CssSelector("._1p1t"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].parentNode.removeChild(arguments[0])", myElementRemoveDiv);
IWebElement myElement = driver.FindElement(By.CssSelector("._1mf > span:nth-child(1)"));
String StrInnerHtml = "<span data-text=\"true\">Entering text</span>";
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].innerHTML=" + "'" + StrInnerHtml + "'", myElement);
Пока приведенный выше код успешно выполненв состоянии ввести текст, но при нажатии кнопки Далее текст не будет отправлен.Любая помощь будет принята с благодарностью.