使用硒在带有表单控件的框中输入文本

modLmakur

我下面的代码试图将文本输入到水平形式的单元格中。我正在使用硒,该页面的来源类似于下面的示例来源。当我运行下面的代码尝试通过id标识元素时,出现以下错误。有人知道这个问题可能是什么,您能建议如何解决吗?

资源:

<div class="form-group" id="questionaire0"><div class="col-sm-11 question"><h5>Please write your Full Name<small> (Briefly respond below)</small></h5></div><div class="col-sm-11"><textarea name="questionaire0" class="form-control"></textarea></div></div>

码:

driver.find_element_by_id("questionaire0").send_keys(‘Test Name’)

time.sleep(1)

错误:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-54-c78e15aec19b> in <module>()
      1 
      2 
----> 3 driver.find_element_by_id("questionaire0").send_keys('Test Name')
      4 
      5 time.sleep(1)

~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py in send_keys(self, *value)
    477         self._execute(Command.SEND_KEYS_TO_ELEMENT,
    478                       {'text': "".join(keys_to_typing(value)),
--> 479                        'value': keys_to_typing(value)})
    480 
    481     # RenderedWebElement Items

~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py in _execute(self, command, params)
    626             params = {}
    627         params['id'] = self._id
--> 628         return self._parent.execute(command, params)
    629 
    630     def find_element(self, by=By.ID, value=None):

~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
    318         response = self.command_executor.execute(driver_command, params)
    319         if response:
--> 320             self.error_handler.check_response(response)
    321             response['value'] = self._unwrap_value(
    322                 response.get('value', None))

~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

WebDriverException: Message: unknown error: cannot focus element
  (Session info: chrome=72.0.3626.109)
  (Driver info: chromedriver=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8),platform=Mac OS X 10.12.6 x86_64)
昆杜克

您的Textarea字段没有名为的属性id。您使用属性。name它应该起作用。

driver.find_element_by_name("questionaire0").send_keys('Test Name')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

硒-无法选择带有ID的输入框

如何使用Angular JS在带有输入字段的文本框中添加文本并将其从文本框中删除?

带有文本输入的对话框

如何使用硒将值输入文本框?

带有 name='' 的无效表单控件在表单中不可聚焦

Google脚本:使用表单中的输入文本框从表单中提取项目并显示为选项

在html5输入框中带有文本类型的微调框?

在有角网格中,我在嵌入式Kendo网格中有一列带有编辑器模板(反应形式)的列。它不链接模板控件(文本框)和表单

Mozilla Firefox 中带有选择标签的表单控件显示文本,但 Chrome 中的相同组件不显示

如何使用带有Java表单格式值的select创建新的输入文本?

在C#Windows窗体中如何在带有***的文本框中输入密码?

如何在Xamarin表单中创建带有或不带有Web视图的富文本框?

无法通过VBA使用硒在搜索框中输入值

使用带有模板驱动表单 angular 的控件

表单验证中的文本输入输出消息框用尽

在文本框中输入Enter时提交ajax表单

如何使HTML中的表单输入框(以及文本)变大?

访问表单将不接受文本框中的输入

从VB模块中的访问表单引用文本框输入

创建带有两个文本框的HTML UI表单。使用Google电子表格中的回复

文本框从右到左输入,左侧带有减号“-”

Xamarin形式的带有文本输入的弹出对话框

使用带有复选框的表单中的输入进行查询

在文本框中没有文本就无法输入

使用硒清除HTML输入框

带有控件的表单级别的KeyPress

无法从硒中的输入元素获取文本

带有Angular的选择框中的表单组绑定

带有在表单中创建输入的按钮的问题