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

每当我运行这段代码时,它都会显示"chromeDriver没有诸如Find_Element_by_XPath这样的属性",但我看到其他人在他们的代码中这样使用它.

推荐答案

您正在使用不推荐使用的语法.如果您想要使用XPath定位器,则需要做以下工作:

[...]
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]')

请复习Selenium documentation分.

Python相关问答推荐

如何使用matplotlib在Python中使用规范化数据和原始t测试值创建组合热图?

Python json.转储包含一些UTF-8字符的二元组,要么失败,要么转换它们.我希望编码字符按原样保留

运行总计基于多列pandas的分组和总和

海运图:调整行和列标签

在Mac上安装ipython

为什么np. exp(1000)给出溢出警告,而np. exp(—100000)没有给出下溢警告?

PYTHON、VLC、RTSP.屏幕截图不起作用

通过追加列表以极向聚合

Polars map_使用多处理对UDF进行批处理

BeautifulSoup-Screper有时运行得很好,很健壮--但有时它失败了::可能这里需要一些更多的异常处理?

递归函数修饰器

如何在GEKKO中使用复共轭物

提取数组每行的非零元素

numpy数组和数组标量之间的不同行为

用fft计算指数复和代替求和来模拟衍射?

如何在Python中将超链接添加到PDF中每个页面的顶部?

Pandas:计数器的滚动和,复位

Pythonquests.get(Url)返回Colab中的空内容

按最大属性值Django对对象进行排序

如何在networkx图中提取和绘制直接邻居(以及邻居的邻居)?