2

В Вконтакте есть "написать сообщение":

<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 - попадается два раза, тот, который интересует - второй

  1. Такое написание будет правильно?

driver.find_element_by_class_name('im-chat-input--text[1]')

  1. Как найти элемент с ID im_editable450262838 по маске типа im_editable*?

driver.find_element_by_id('im-chat-input--text*')

  1. Можно ли в Selenium искать через MATCH, чтобы просто вставить кусок кода, по примеру, и потом ввести значения:

driver.find_MATCH ('class ="im_editable im-chat-input--t')

1 ответ 1

2
  1. Правильно будет так:

    el = driver.find_elements_by_class_name('im-chat-input--text')[1]


  1. Поиск по маске im_editable*:

    el = driver.find_element_by_xpath("//div[starts-with(@id,'im_editable')]")


  1. Поиск по куску кода

    Любой самый сложный элемент состоит из атрибутов и их значений. Используйте 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

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.