Home > Mobile >  Python 3.9 Selenium click () does not work (Vimeo)
Python 3.9 Selenium click () does not work (Vimeo)

Time:11-04

I tried to click the button through selenium, but the website's HTML code seems like it blocks users to do that. (I am new to python and stuffs so not sure what it is.)

import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains


#others
from bs4 import BeautifulSoup
import time
import pandas as pd
driver = webdriver.Chrome()


for i in range (1,10):
    url = 'https://vimeo.com/user22715452'
    driver.get(url)

folder = driver.find_element(By.XPATH,"//button[@class='sc-bkkeKt LtbA-D']")
folder.click

This is my code and this is the website's html button code and Xpath

<button format="primary" ><span >Load more</span><svg viewBox="0 0 20 20"><path d="M14.5 10.4l-3.4 3.5V2H8.9v11.9l-3.4-3.5L4 11.9l6 6.1 6-6.1z"></path></svg><div radius="50" ></div></button>
//*[@id="__next"]/div[4]/div[2]/div[2]/div[2]/section/section/section/section/button>

When I tried to with other website, it works well, but vimeo is the only website that I cannot see exact xpath. In this case, should I need to find iframe and changed to xpath?

The error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@class='sc-bkkeKt LtbA-D']"} (Session info: chrome=107.0.5304.87)

CodePudding user response:

I think you are trying this:

# Needed libs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# We create the driver
driver = webdriver.Chrome()

# We maximize the window, because if not the page will be different
driver.maximize_window()

# We navigate to the url
url = 'https://vimeo.com/user22715452'
driver.get(url)

# We wait for the "Load more" button and click on it. We repeat this action 10 times. You can repeat it as many times as you want
for i in range(0, 10):
    WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//button[@class='sc-bkkeKt LtbA-D']"))).click()

CodePudding user response:

Maybe try and access the element using JS.

  • Related