[英]How to SendKeys to a div element with coleditable="true" using Selenium and C#
There is an element I can't figure out how to type text into it.有一个元素我无法弄清楚如何在其中键入文本。
<div class="floatstart gridcell grideditablefield" colname="Items" coltype="string" coleditable="true" val="" style="width: 107px; overflow: hidden; cursor: text; height: 100%;"> </div>
Without code (manually) in order to put text in it I need to click on it twice, so in the code If I click on the element once, the class seems to change to:没有代码(手动)为了在其中放置文本我需要点击它两次,所以在代码中如果我点击一次元素,class 似乎变为:
<div class="floatstart gridcell grideditablefield activecell"...> </div>
And when I click on the element again it changes once more to当我再次单击该元素时,它再次变为
<div class="floatstart gridcell grideditablefield activecell NDColEditableInEdit"...> </div>
Anyway, once I try to send keys to it I get an Error:无论如何,一旦我尝试向它发送密钥,我就会收到一个错误:
OpenQA.Selenium.ElementNotVisibleException: 'element not interactable
(Session info: chrome=//doesn't matter)
(Driver info: chromedriver=//doesn't matter (6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896@{#875}),platform=Windows NT 10.0.19042 x86_64)'
Code:代码:
// It does find the right element
var element = driverReUse.FindElementByXPath("//*[@id='CalcOfAmmountsData']/div/div[2]/div/div[1]/div[2]");
element.Click();
element.Click();
element.SendKeys("keys");
Please help请帮忙
Try the below,试试下面,
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.xpath("//[@id='CalcOfAmmountsData']/div/div[2]/div/div[1]/div[2]"))).doubleClick().build().perform();
act.sendKeys('Keys');
Please make the changed if any required for c#
, in above.如果
c#
有任何需要,请在上面进行更改。
Hope this answer your question.希望这能回答你的问题。
Generally <div>
tags are not interactable unless it contains the attribute contenteditable="true"
.通常
<div>
标签不可交互,除非它包含属性contenteditable="true"
。
As you mentioned, initially the <div>
element is:正如您所提到的,最初
<div>
元素是:
<div class="floatstart gridcell grideditablefield" colname="Items" coltype="string" coleditable="true" ...> </div>
After first click:第一次点击后:
<div class="floatstart gridcell grideditablefield activecell" colname="Items" coltype="string" coleditable="true" ...> </div>
After second click:第二次点击后:
<div class="floatstart gridcell grideditablefield activecell NDColEditableInEdit" colname="Items" coltype="string" coleditable="true" ...> </div>
As per this and this discussion either after the first or second click an <input>
/ <textarea>
gets added, where you need to send the character sequence as follows:根据这个和这个讨论,在第一次或第二次点击后添加了一个
<input>
/ <textarea>
,您需要在其中发送字符序列,如下所示:
// It does find the right element
var element = driverReUse.FindElementByXPath("//*[@id='CalcOfAmmountsData']/div/div[2]/div/div[1]/div[2]");
element.Click();
element.Click();
var input = driverReUse.FindElementByXPath("xpath_input_textarea");
input.SendKeys("keys");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.