<table class="gridtable" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true" gwtcellbasedwidgetimpldispatchingblur="true" style="width: 100%;">
<thead>
<colgroup>
<tbody style="">
<tr class="GORM0XEDKD GORM0XEDME" onclick="">
<td class="GORM0XEDJD GORM0XEDLD GORM0XEDMD GORM0XEDNE">
<td class="GORM0XEDJD GORM0XEDLD GORM0XEDNE GORM0XEDGE">
<div style="outline:none;" tabindex="0"></div>
</td>
</tr>
</tbody>
<tbody style="display: none;">
<tfoot style="display: none;">
</table>
Xpath for the text field -
EmailTemplateEditorTemplateName= By.xpath("//*[contains(@class,'GORM0XEDJD GORM0XEDLD GORM0XEDNE GORM0XEDGE')]/div[1]");
尝试以下选项。但所有都未能将文本发送到EmailTemplateEditorTemplateName文本字段
1. driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).sendKeys("yahooo");
2. this.WaitForElement(DesignerLocators.EmailTemplateEditorTemplateName);
WebElement tempname = driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
JavascriptExecutor rightexecutor = (JavascriptExecutor)driver;
rightexecutor.executeScript("arguments[0].setAttribute('value','yahoo')", tempname);
3. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
Actions builder = new Actions(driver);
builder.moveToElement(Element).sendKeys("yahoo").build().perform();
4. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
Actions builder = new Actions(driver);
builder.moveToElement(Element).click().sendKeys("yahoo").build().perform();
5. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
Actions builder = new Actions(driver);
builder.moveToElement(Element).click(Element).sendKeys("yahoo").build().perform();
click()正在运行。
答案 0 :(得分:2)
你试过这个:
既然你说Click工作,
driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).click();
driver.switchTo().activeElement().sendKeys("Text");
或尝试使用构建器click和activeElement,如下所示
builder.moveToElement(Element).click();
driver.switchTo().activeElement().sendKeys("Text");
答案 1 :(得分:1)
Selenium / Webdriver中没有直接选项来设置“div”标签中的值。
您需要使用innerHTML
设置属性JavascriptExecutor
,如下所示:
this.WaitForElement(DesignerLocators.EmailTemplateEditorTemplateName);
WebElement tempname = driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
JavascriptExecutor rightexecutor = (JavascriptExecutor)driver;
rightexecutor.executeScript("arguments[0].setAttribute('innerHTML','yahoo')", tempname);
答案 2 :(得分:0)
根据浏览器版本检查并查看驱动程序(chromeor firefox)上的最新版本。请先进行此基本验证。这主要解决了这个问题。