html - Selenium - 无法选择带有 id 的输入框

标签 html css selenium xpath

我的 HTML

<td>
  <iframe id="Name_IF" style="left: auto; top: auto; width: 100%; height: 22px; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; margin-top: auto; margin-right: auto; margin-bottom: auto; margin-left: auto; vertical-align: bottom; border-top-color: rgb(112,112,112); border-right-color: rgb(112,112,112); border-bottom-color: rgb(112,112,112); border-left-color: rgb(112,112,112); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; float: none; display: inline; position: static; background-color: white;"
  src="/a.rapidspellweb?t=r&n=blank.html" tabindex="0" frameborder="0">
    <html spellcheck="false">

    <head>

      <body class="RS_SingleLineTB" style="color: rgb(33,33,33); line-height: normal; letter-spacing: normal; overflow: hidden; clear: none; font-family: MS Shell Dlg; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: auto; 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; float: none; list-style-type: disc; list-style-position: outside; list-style-image: none; page-break-before: auto; page-break-after: auto; cursor: auto; unicode-bidi: normal; direction: ltr; ruby-align: auto; ruby-position: above; ruby-overhang: auto; layout-grid-char: none; layout-grid-line: none; layout-grid-mode: both; layout-grid-type: loose; overflow-x: hidden; overflow-y: hidden; zoom: normal; layout-flow: horizontal; writing-mode: lr-tb; caption-side: top; box-sizing: content-box; orphans: 2; widows: 2; page-break-inside: auto; empty-cells: show; background-image: none; background-attachment: scroll; background-repeat: repeat; background-position-x: 0%; background-position-y: 0%; background-color: rgb(255, 255, 255);"
      contentEditable="true" onload="loaded=true;">
        <nobr/>
<input name="Description" id="Name" style="width: 100%; display: none;" onchange=" HE(event,this,'applylogic');" ChangeMessage="applylogic" jQuery17108595534879847912="5" rsw_extension="[object Object]" spellchecktimeoutid="21" />

我需要在输入框输入一段文字,但是找不到带ID的输入框。此外,在 IE 中使用开发人员工具时,当我选择时,

<input name="Description" id="Name" style="width: 100%; display: none;" onchange=" HE(event,this,'applylogic');" ChangeMessage="applylogic" jQuery17108595534879847912="5" rsw_extension="[object Object]" spellchecktimeoutid="21" />

没有突出显示。输入字段在选择时突出显示,

<body class="RS_SingleLineTB" style="color: rgb(33,33,33); line-height: normal; letter-spacing: normal; overflow: hidden; clear: none; font-family: MS Shell Dlg; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: 400; vertical-align: auto; 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; float: none; list-style-type: disc; list-style-position: outside; list-style-image: none; page-break-before: auto; page-break-after: auto; cursor: auto; unicode-bidi: normal; direction: ltr; ruby-align: auto; ruby-position: above; ruby-overhang: auto; layout-grid-char: none; layout-grid-line: none; layout-grid-mode: both; layout-grid-type: loose; overflow-x: hidden; overflow-y: hidden; zoom: normal; layout-flow: horizontal; writing-mode: lr-tb; caption-side: top; box-sizing: content-box; orphans: 2; widows: 2; page-break-inside: auto; empty-cells: show; background-image: none; background-attachment: scroll; background-repeat: repeat; background-position-x: 0%; background-position-y: 0%; background-color: rgb(255, 255, 255);"
contentEditable="true" onload="loaded=true;">
HTML structure(in Developer tools on selecting the input field this code gets selected) 使用 ID 找不到元素。如何使用 xpath 查找输入字段?

如果我的问题有任何错误,请原谅我。

最佳答案

我正在使用 Selenium 的 Java 绑定(bind)

你需要先切换到iframe

WebElement iframe = driver.findElement(By.id("Name_IF"));
driver.switchTo().frame(iframe);

WebElement inputElement = driver.findElement(By.id("Name"));

关于html - Selenium - 无法选择带有 id 的输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33648217/

相关文章:

javascript - 表单数据在新页面中不可见 - PHP + Javascript

css - 为什么 Chrome 打破了这种布局?

css - ngGrid 和 uiGrid 之间的区别?

javascript - 网站内容中超出页脚的代码

java - 如何为 div 和类创建的结账创建 xpath

java - 带有 chromedriver 的 Selenium 根据 "headless"参数给出不同的结果

javascript - 我怎样才能要求用户打开他们的蓝牙?使用javascript

html - margin、padding、border 都为零后还有空间吗?

javascript - NVD3 示例图表未显示

python-3.x - cookie sqlite错误1555如何解决? ( python 和 Selenium )