
Всплывающее окно
Я использую здесь код Python... но не знаю, почему, потому что он продолжает сообщать об ошибке.
Код: Выделить всё
"Message: invalid selector: Unable to locate an element with the xpath expression .//span[contains(text(), 'What's on your mind, Myth?')] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string './/span[contains(text(), 'What's on your mind, Myth?')]' is not a valid XPath expression."
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
from selenium.webdriver.common.by import By
# import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import time
import random
import string
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
# Create a webdriver object for Chrome and set the window size
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.set_window_size(1200, 800)
auto_link = 'https://facebook.com/'
driver.get(auto_link)
email = driver.find_element(By.XPATH, ".//*[@id='email']")
password = driver.find_element(By.XPATH, ".//*[@id='pass']")
# login_button = driver.find_element(By.XPATH, ".//*[@id='u_0_5_jA']")
login_button = driver.find_element(By.XPATH, "./html/body/div[1]/div[1]/div[1]/div/div/div/div[2]/div/div[1]/form/div[2]/button")
# //*[@id="mount_0_0_jy"]/div/div[1]/div/div[3]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div/div[3]/div/div[2]/div/div/div/div[1]/div/div[1]
# //*[@id="scrollview"]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div/div[3]/div/div[2]/div/div/div/div[1]/div/div[1]/span
# /html/body/div[1]/div/div[1]/div/div[3]/div/div/div/div[1]/div[1]/div/div[2]/div/div/div/div[3]/div/div[2]/div/div/div/div[1]/div/div[1]/span
# email
# //*[@id="email"]
email.click()
email.send_keys("xxxxxx")
#pass
# //*[@id="pass"]
password.click()
password.send_keys("XXXXX")
login_button.click()
# Click on the "What's on your mind" button
whats_on_your_mind_button = driver.find_element(By.XPATH, ".//span[contains(text(), 'What\'s on your mind, Myth?')]")
whats_on_your_mind_button.click()
time.sleep(1000)
driver.quit()
Подробнее здесь: https://stackoverflow.com/questions/775 ... -in-python
Мобильная версия