I am trying to use find_element_by_xpath with using undetected chromedriver but could not figure out how.Someone may help me please?
import tempfile
import undetected_chromedriver as webdriver
import sys
import selenium
import threading
from threading import Thread
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
from bs4 import BeautifulSoup
# Set up the Chrome options
# Set up the undetected_chromedriver instance
options = webdriver.ChromeOptions()
profile = "C:\\Users\\merta\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
options.add_argument(f"user-data-dir={profile}")
browser = webdriver.Chrome(options=options,use_subprocess=True)
browser.get("https://www.hepsiburada.com/laptop-notebook-dizustu-bilgisayarlar-c-98")
element=browser.find_element_by_xpath('//*[@id="oldHeader_5b475cae-5271-48a4-2ce4-e5ad94851cd0"]/div/div[1]/div[2]/ul/li[3]')
type here
Whenever I run this code it says "chromedriver has no attributes such as find_element_by_xpath" but I saw other people use it in their codes like that.
You are using deprecated syntax. If you want to use XPATH locators, you need to something along these lines:
[...]
from selenium.webdriver.common.by import By
[...]
desired_element = driver.find_element(By.XPATH,'//*[@id="oldHeader_5b475cae-5271-48a4-2ce4-e5ad94851cd0"]/div/div[1]/div[2]/ul/li[3]')
Please review Selenium documentation.