将键发送到元素硒 python
Send keys to element selenium python
我正在编写一个脚本来自动为我填写表格,但我正在努力 'find element'。我检查的时候可以看到,但是我不能让它向占位符发送信息。
这是我正在尝试 send_keys 的元素。
<input type="text" placeholder="Next step" class="pl-10 pr-12 form-input block w-full py-2 px-3 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5" required="" value="">
这是父元素。
<div class="nested-fields air-pipeline-step-item" draggable="true" data-handler-id="T0" style="opacity: 1;"><input name="vacancy[vacancy_pipeline_steps_attributes][0][id]" type="hidden" value=""><input name="vacancy[vacancy_pipeline_steps_attributes][0][step_order]" type="hidden" value="0"><input name="vacancy[vacancy_pipeline_steps_attributes][0][display_name]" type="hidden" value="Awaiting Review">
尝试时:
self.driver.find_element_by_name('vacancy[vacancy_pipeline_steps_attributes][0][id]').click()
我得到:
ElementNotVisibleException: Message: element not visible
我想点击这个元素然后给它赋值。有关如何执行此操作的任何建议?
您可以使用 find_element_by_class_name() 方法查找元素并发送密钥。所以代码看起来像这样。
// driver should be initialized before
field = driver.find_element_by_class_name("class_name")
field.sendKeys("key")
我会在这里使用 css 选择器——允许选择更多的元素:
css_selector = 'div[class*="nested-fields"][class*="air-pipeline-step-item"] > input[type="text"]'
# Easier to navigate try and excepts with find many
my_input = self.driver.find_elements_by_css_selector(css_selector)
if my_input:
my_input = my_input[0]
else:
# Try a diff selector – or raise an error
raise ValueError(f'couldn\'t find an element with using {css_selector=}')
# Continue code here
my_input.send_keys('Hello World!')
我正在编写一个脚本来自动为我填写表格,但我正在努力 'find element'。我检查的时候可以看到,但是我不能让它向占位符发送信息。
这是我正在尝试 send_keys 的元素。
<input type="text" placeholder="Next step" class="pl-10 pr-12 form-input block w-full py-2 px-3 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5" required="" value="">
这是父元素。
<div class="nested-fields air-pipeline-step-item" draggable="true" data-handler-id="T0" style="opacity: 1;"><input name="vacancy[vacancy_pipeline_steps_attributes][0][id]" type="hidden" value=""><input name="vacancy[vacancy_pipeline_steps_attributes][0][step_order]" type="hidden" value="0"><input name="vacancy[vacancy_pipeline_steps_attributes][0][display_name]" type="hidden" value="Awaiting Review">
尝试时:
self.driver.find_element_by_name('vacancy[vacancy_pipeline_steps_attributes][0][id]').click()
我得到:
ElementNotVisibleException: Message: element not visible
我想点击这个元素然后给它赋值。有关如何执行此操作的任何建议?
您可以使用 find_element_by_class_name() 方法查找元素并发送密钥。所以代码看起来像这样。
// driver should be initialized before
field = driver.find_element_by_class_name("class_name")
field.sendKeys("key")
我会在这里使用 css 选择器——允许选择更多的元素:
css_selector = 'div[class*="nested-fields"][class*="air-pipeline-step-item"] > input[type="text"]'
# Easier to navigate try and excepts with find many
my_input = self.driver.find_elements_by_css_selector(css_selector)
if my_input:
my_input = my_input[0]
else:
# Try a diff selector – or raise an error
raise ValueError(f'couldn\'t find an element with using {css_selector=}')
# Continue code here
my_input.send_keys('Hello World!')