[英]In Selenium WebDriver, how do I find an element with a DOM ID and no className?
The element I am trying to manipulate is a drop down autocomplete text box. 我尝试操作的元素是下拉自动填充文本框。 However rather than be a normal text box its this:
但是,这不是普通的文本框:
<input class="rad-input acInput float_left edScheduleList
ui-autocomplete-input" style="width: 234px; font-size: 12px;
font-family: Segoe UI, Arial, Times New Roman; padding-left: 4px;
line-height: 12px;" placeholder="Select Schedule..." data-bind="click: _editorOverlay.Overlay.CustomRecVM.scheduleData.ac.dropdownArrowClick,
enable: _editorOverlay.Overlay.CustomRecVM.scheduleEnabled,
jqAuto: { autoFocus: true },
jqAutoSource: editorOverlay.Overlay.CustomRecVM.scheduleData.list,
jqAutoQuery: editorOverlay.Overlay.CustomRecVM.scheduleData.GetList,
jqAutoValue: _editorOverlay.Overlay.CustomRecVM.scheduleData.selectedID,
jqAutoSourceLabel: 'Text',
jqAutoSourceInputValue: 'Text',
jqAutoSourceValue: 'Value',
jqChange: _editorOverlay.Overlay.CustomRecVM.ScheduleIndexChanged" id="domId08015369399681067" autocomplete="off">
I can't find it by id, cssSelector, xpath, className, name, or class. 我无法通过id,cssSelector,xpath,className,名称或类找到它。 I have tried partial or containing text and am still getting no where.
我已经尝试过部分或包含文本,但仍然无法获取任何内容。 I am using Java for this.
我为此使用Java。
I found out I could just use cssSelector for the class name. 我发现我可以只使用cssSelector作为类名。 I am still relatively new to Selenium and did not know I could combine class names and cssSelector methods.
我对Selenium还是比较陌生,不知道我可以结合使用类名和cssSelector方法。 The above element can be manipulated with the following code:
可以使用以下代码来操纵上述元素:
driver.findElement(By.cssSelector
("input[class='rad-input acInput float_left edScheduleList ui-autocomplete-input']"));
Thanks for the help guys, the class name was really throwing me off. 谢谢你们的帮助,班级名称真的让我失望。 I thought because the selector was coming back as a dom I had to treat it differently.
我以为,因为选择器要作为dom回来,所以我不得不以不同的方式对待它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.