文件路径字段无法使用Selenium(Python)填充。

huangapple go评论63阅读模式
英文:

File pathway field cannot be filled with Selenium (Python)

问题

我尝试添加一个需要使用Selenium(Chromedriver)上传的文件路径,但失败了。我的疑惑是是否可以使用标签autocomplete="off"。

Input:

<input id="loadFileControl-1287-inputEl" type="text" role="textbox" size="1" name="" readonly="readonly" class="x-form-field x-form-required-field x-form-text x-form-invalid-field x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" data-errorqtip="<ul class=&quot;x-list-plain&quot;><li>This field is required</li></ul>" style="width: 100%;">

我的Selenium尝试:

input_field = driver.find_element("xpath", "//input[@class='x-form-field x-form-required-field x-form-text x-form-invalid-field x-form-focus x-field-form-focus x-field-default-form-focus']")
input_field.send_keys('file_name.xml')

input_field.click()有效,所以我认为我正确地指向了元素。
谢谢。

英文:

I tried to add a path to file that needs to be uploaded with Selenium (Chromedriver) and failed. My doubt is if it is possible with tag autocomplete="off".
Input:

&lt;input id=&quot;loadFileControl-1287-inputEl&quot; type=&quot;text&quot; role=&quot;textbox&quot; size=&quot;1&quot; name=&quot;&quot; readonly=&quot;readonly&quot; class=&quot;x-form-field x-form-required-field x-form-text x-form-invalid-field x-form-focus x-field-form-focus x-field-default-form-focus&quot; autocomplete=&quot;off&quot; data-errorqtip=&quot;&lt;ul class=&amp;quot;x-list-plain&amp;quot;&gt;&lt;li&gt;This field is required&lt;/li&gt;&lt;/ul&gt;&quot; style=&quot;width: 100%;&quot;&gt;

My attempt in Selenium:

input_field = driver.find_element(&quot;xpath&quot;, &quot;//input[@class=&#39;x-form-field x-form-required-field x-form-text x-form-invalid-field x-form-focus x-field-form-focus x-field-default-form-focus&#39;]&quot;)
input_field.send_keys(&#39;file_name.xml&#39;)

input_field.click() works so I assume I point the element correctly.
Thank you.

答案1

得分: 1

你试图输入的字段是只读的。你可以点击它,但是正如属性所示,你无法编辑它。

<input id="loadFileControl-1287-inputEl" type="text" role="textbox" size="1" name="" readonly="readonly" class="x-form-field x-form-required-field x-form-text x-form-invalid-field x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" data-errorqtip="<ul class=&quot;x-list-plain&quot;><li>This field is required</li></ul>" style="width: 100%;">

英文:

The field youre trying to input into is read only. You can click on it but like the attribute says, you cant edit it.

&lt;input id=&quot;loadFileControl-1287-inputEl&quot; type=&quot;text&quot; role=&quot;textbox&quot; size=&quot;1&quot; name=&quot;&quot; readonly=&quot;readonly&quot; class=&quot;x-form-field x-form-required-field x-form-text x-form-invalid-field x-form-focus x-field-form-focus x-field-default-form-focus&quot; autocomplete=&quot;off&quot; data-errorqtip=&quot;&lt;ul class=&amp;quot;x-list-plain&amp;quot;&gt;&lt;li&gt;This field is required&lt;/li&gt;&lt;/ul&gt;&quot; style=&quot;width: 100%;&quot;&gt;

huangapple
  • 本文由 发表于 2023年3月7日 15:20:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658991.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定