[英]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-item
和KambiBC-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.