Reputation: 65
I want to click the 1st item, I tried locating it by using find element xpath, tag name, but im getting an error
Upvotes: 1
Views: 180
Reputation: 3541
first you should realize, that selector what you're trying to interract with the page is not unique and class name is not enough to get the particular one
second I would suggest again using explicitly waits:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
timeout = 30
driver = webdriver.Chrome()
driver.get('https://weed.com/product-category/cbd/')
element = WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.XPATH, "(//a[@class='woocommerce-LoopProduct-link woocommerce-loop-product__link'])[1]")))
element.click()
driver.quit()
if you want to click on the particular element, I would suggest using text and action-perform:
timeout = 30
driver = webdriver.Chrome()
driver.get('https://weed.com/product-category/cbd/')
element = WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.XPATH, "//h2[text()='Binoid Good Night CBD Oil – Sleep Blend']")))
action = ActionChains(driver)
action.move_to_element(element).click().perform()
driver.quit()
Upvotes: 1