@puszkin

Как найти элемент xpath selenium facebook «Введите сообщение»?

5c1161d8bd914102682906.jpeg
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time,random
import traceback;#uotput error


text_message = "hi! how are you"

akki_url = 'https://www.facebook.com/patrycja.springer/'


driver = webdriver.Chrome()
#driver = webdriver.Firefox()


driver.get('https://www.facebook.com/')#.maximize_window()#.implicitly_wait(20)
driver.maximize_window()
#driver.manage().window().maximize();
time.sleep(10)
element = driver.find_element_by_id("email") #находим поле с email
element.send_keys("Логин")#вводим значение

element = driver.find_element_by_id("pass") #находим поле с пароля
element.send_keys("Пароль", Keys.ENTER)#вводим значение и нажимаем ентер 

time.sleep(5)
driver.get(akki_url)#open link akki
time.sleep(5)
driver.find_element_by_tag_name("body").send_keys('', Keys.ESCAPE)
driver.find_element_by_tag_name("body").send_keys('', Keys.ESCAPE)
driver.find_element_by_tag_name("body").send_keys('', Keys.ESCAPE)

t=driver.page_source
time.sleep(5)

n_kommandy = 1
proverka = 0
try:
    #element = driver.find_element_by_partial_link_text("Сообщение").send_keys(text_message, Keys.ENTER)
    driver.find_element_by_tag_name("body").send_keys('', Keys.ESCAPE)
    element = driver.find_element_by_link_text('Сообщение').send_keys('Hi', Keys.ENTER)
    time.sleep(5)
     
     
    proverka = 1
    print ('выполнил команду НАПИСАТЬ'+str(n_kommandy))
except Exception as exc:
    print(exc)
    traceback.print_exc()
    print ('ошибка команда НАПИСАТЬ'+str(n_kommandy))
n_kommandy +=1

#driver.get(akki_url) #open page user


        
        
        

#driver.find_element_by_class_name("_1p1v")

#driver.find_element_by_xpath('//div[@class="_1mf _1mj"]').send_keys('Hi', Keys.ENTER)


#driver.find_element_by_xpath('//div[@class="_1mf _1mj"]/input').send_keys('Hi', Keys.ENTER)



n_kommandy = 1
proverka = 0
#___________________1

try:
    element = driver.find_element_by_xpath(u"//span[@id='cch_f2e9bc13ce9c558' and contains(@class, '_mh6')]/div/div[contains(@class, '_5rp7')]/div[contains(@class, '_5rpb')]/div[contains(@class, 'notranslate')]/div/div/div[contains(@class, '_1mf')]").send_keys(text_message, Keys.ENTER)
    proverka = 1
    
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nвыполнил команду '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
except Exception as exc:
    print(exc)
    traceback.print_exc()
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nошибка команда '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')

n_kommandy +=1
#___________________2
try:
    
    element = driver.find_element_by_xpath(u"/div/div/div[contains(@class, '_1mf')]").send_keys(text_message, Keys.ENTER)
    #element = driver..click()
    proverka = 1
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nвыполнил команду '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
except Exception as exc:
    print(exc)
    traceback.print_exc()
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nошибка команда '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
n_kommandy +=1
#___________________3
try:
    
    
    element = driver.find_element_by_xpath(u"//span[@id='cch_f2e9bc13ce9c558' and contains(@class, '_mh6')]").send_keys(text_message, Keys.ENTER)
    proverka = 1
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nвыполнил команду '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
except Exception as exc:
    print(exc)
    traceback.print_exc()
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nошибка команда '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
n_kommandy +=1
#___________________7
try:
     
    element = driver.find_element_by_xpath(u"/div/div[contains(@class, '_5rp7')]").send_keys(text_message, Keys.ENTER)   
    #element = driver.find_element_by_xpath("").send_keys(text_message, Keys.ENTER)
    #element = driver..click()
    proverka = 1
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nвыполнил команду '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
except Exception as exc:
    print(exc)
    traceback.print_exc()
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nошибка команда '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
n_kommandy +=1
#___________________
try:
    element = driver.find_element_by_xpath(u"/div[contains(@class, '_5rpb')]").send_keys(text_message, Keys.ENTER)
    #element = driver..click()
    proverka = 1
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nвыполнил команду '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
except Exception as exc:
    print(exc)
    traceback.print_exc()
    print ('\n_+_+_+_+_+_+_+_+_+_+\n\nошибка команда '+str(n_kommandy)+'\n_+_+_+_+_+_+_+_+_+_+\n\n')
n_kommandy +=1



   
time.sleep(5)
driver.find_element_by_id("js_9c").click()#закрыть сообщение
  • Вопрос задан
  • 211 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы