简体   繁体   English

带有Firefox Web驱动程序的Selenium无法通过Python代码找到元素

[英]Selenium with Firefox web driver can not find elements by Python code

I can not find elements by using Firefox web driver, it print 0: 我无法使用Firefox Web驱动程序找到元素,它显示0:

driver = webdriver.Firefox()
driver.get("https://www.unibet.ro/betting#filter/football")

 event = driver.find_elements_by_class_name('KambiBC-event-item KambiBC-event-item--type-match')
 print (len(event))

But it works when I change the web driver to Edge: driver = webdriver.Edge() , as i also have the edge web driver set up in my Path environments, printing the right amount of web elements 但是当我将Web驱动程序更改为Edge时,它可以工作: driver = webdriver.Edge() ,因为我也在Path环境中设置了Edge Web驱动程序,从而打印了适量的Web元素

在此处输入图片说明

Looks like the elements you're trying to find are defined with two classes ( KambiBC-event-item and KambiBC-event-item--type-match ). 看来您要查找的元素是由两个类定义的( KambiBC-event-itemKambiBC-event-item--type-match )。

I believe driver.find_elements_by_class_name() expects a single class name as an argument, and hence it's not working in your case. 我相信driver.find_elements_by_class_name()需要一个类名作为参数,因此在您的情况下不起作用。

You can try to use the find_elements_by_xpath() method instead as below (Pl replace the //* in the xpath with the appropriate element tag name): 您可以尝试改为使用find_elements_by_xpath()方法,如下所示(请用适当的元素标记名将xpath中的//*替换为//* ):

event = driver.find_elements_by_xpath("//*[@class='KambiBC-event-item KambiBC-event-item--type-match']")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于Python中Selenium的Firefox Web驱动程序 - Firefox web driver for Selenium in Python Python Selenium Chrome驱动程序找不到元素 - Python Selenium Chrome Driver doesnt find elements selenium firefox驱动程序python - selenium firefox driver python Selenium Web驱动程序| 查找对象 蟒蛇 - Selenium Web Driver | Find object | Python 使用 Selenium Python 在网页上找不到元素 - Can't find elements on web page using Selenium Python 如何在 python 上获取 selenium web 驱动程序以在以下页面的 ZC7A628CBA22E28EB17B5F5C6AE2A26 上查找元素? - How to get selenium web driver on python to find elements on css selectors of a following page? 如何在 Z23EEEB4347BDD755BFC6B7EE9A 中使用 selenium firefox 和 chrome 驱动程序翻译 web 页面? - How to translate a web page using selenium firefox and chrome driver in python? 如何通过使用 driver.find_elements(By.XPATH,'') 和 Python Selenium 来获取汽车名称 - How can i get car names by using driver.find_elements(By.XPATH,'') with Python Selenium Python-Selenium Web驱动程序-在craigslist上找不到“编辑图像”按钮的xpath - Python - Selenium Web Driver - can't find xpath for “edit images” button on craigslist Selenium的网络驱动程序中的隐藏HTML元素(python) - Hidden HTML Elements in Selenium's web driver(python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM