在 Vkontakte 中有一个“写消息”:
<div class="im_editable im-chat-input--text _im_text" tabindex="0" contenteditable="true" id="im_editable450262838" role="textbox" aria-multiline="true"></div>
im-chat-input--text - 出现两次,您感兴趣的是第二次
- 这个拼写正确吗?
driver.find_element_by_class_name('im-chat-input--text[1]')
- 如何
im_editable450262838通过类型掩码查找具有 ID 的元素im_editable*?
driver.find_element_by_id('im-chat-input--text*')
- 根据示例,是否可以使用 MATCH 在 Selenium 中搜索只需插入一段代码,然后输入值:
driver.find_MATCH ('class ="im_editable im-chat-input--t')
这将是正确的:
el = driver.find_elements_by_class_name('im-chat-input--text')[1]按掩码搜索
im_editable*:el = driver.find_element_by_xpath("//div[starts-with(@id,'im_editable')]")按代码搜索
任何最复杂的元素都由属性及其值组成。用于
xpath搜索。一般来说:
driver.find_element_by_xpath("//elementType[@firstAttributeType = 'firstAttributeValue'][@secondAttributeType='secondAttributeValue'][@thirdAttributeType='thirdAttributeValue']....");例如:
driver.find_element_by_xpath("//*[@class='im_editable'][@class='im-chat-input--t']");xpath您可以阅读有关它的更多信息,例如,在XPath 手册中