Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
selenium. xpath error
#1
Hi! why does't it click on the 'agree' button?

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
wait = WebDriverWait(driver, 10)
driver.get('https://www.youtube.com/2lnyn02')

agree_buton = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="yDmH0d"]/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[2]/form[1]/div/div/button')))
agree_buton.click()


time.sleep(500)
Error:
driver = webdriver.Chrome(ChromeDriverManager().install()) DevTools listening on ws://127.0.0.1:56716/devtools/browser/0d4aac93-886e-46b5-bb49-ba6cbde3a56d [6732:6344:1226/142232.382:ERROR:device_event_log_impl.cc(215)] [14:22:32.382] USB: usb_device_handle_win.cc:1045 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) Traceback (most recent call last): File "d:\python visio\automation\web scrapping\api_web\acces_youtube_info.py", line 12, in <module> agree_buton = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="yDmH0d"]/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[2]/form[1]/div/div/button'))) File "C:\Users\i_han\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\support\wait.py", line 87, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Reply
#2
Try using CSS selector,testet work.
agree_button = browser.find_element(By.CSS_SELECTOR, '#yDmH0d > c-wiz > div > div > div > div.NIoIEf > div.G4njw > div.qqtRac > div.VtwTSb > form:nth-child(3) > div > div > button')
agree_button.click()
Should see if can use YouTube Data API v3 woks,before try to scrape YouTube.
Example in in this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium: Click on a Link Error iamaghost 0 1,411 Mar-02-2021, 12:55 AM
Last Post: iamaghost
  Selenium Chrome error Leo_Red 2 1,883 Nov-05-2020, 02:40 PM
Last Post: Leo_Red
  Need Help Typing Text into Tough Form [xpath / selenium] digitalmatic7 0 1,767 Jun-05-2019, 06:46 AM
Last Post: digitalmatic7
  Getting error str object is not callable in find by xpath sumandas89 3 10,806 Aug-14-2018, 03:05 PM
Last Post: mlieqo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020