我正在自动化网页。一个对象没有任何唯一的身份。我应该使用什么作为其唯一标识符,你们能告诉我一些事情吗?这是一个富文本编辑器。我如何将文字输入其中?
当我使用id(ctl00_m_HelpDeskRequestRightColumn_ctl00_txtDetails
)作为其标识符时,它会抛出The expected element "<my object's name>" is not visible
<body class="ms-formbody" scroll="yes" style="border-top-width: medium;
border-right-width: medium; border-bottom-width: medium;
border-left-width: medium; border-top-style: none; border-right-style:
none; border-bottom-style: none; border-left-style: none;
background-color: white;" contentEditable="true" WebLocale="1033"
BaseElementID="ctl00_m_HelpDeskRequestRightColumn_ctl00_txtDetails"
wordWrap="false" ondragdrop="function anonymous() { RTE_OnDrop(this); }"
RestrictedMode="true" AllowHyperlink="true" >
这是该对象的被检查元素描述。
[我使用eclipse在java中编写我的selenium webdriver脚本。]
答案 0 :(得分:0)
试试这个XPath ..
".//body[@BaseElementID='ctl00_m_HelpDeskRequestRightColumn_ctl00_txtDetails']"
答案 1 :(得分:0)
//this should find a collection of all elements having same ids
var elements =Driver.FindElements(By.Id("ctl00_m_HelpDeskRequestRightColumn_ctl00_txtDetails"))
//looping through, find the element that is displayed and then send keys and break the loop
foreach (var element in elements )
{
if (element.Displayed())
{
element.SendKeys("something");
break;
}
}