Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium找不到按钮类名_Python_Selenium_Selenium Webdriver_Web Scraping - Fatal编程技术网

Python Selenium找不到按钮类名

Python Selenium找不到按钮类名,python,selenium,selenium-webdriver,web-scraping,Python,Selenium,Selenium Webdriver,Web Scraping,我看了所有类似的问题,但没能解决我的问题。 Selenium似乎找不到一个按钮,我试图在抓取之前点击它来加载更多页面 在下面的图片中是我在做一些sraping(按钮的类名:btn btn default)之前试图点击的按钮,以加载更多 我所做的: 我使用了Selenium的webdriver。 我尝试使用sleep等待页面加载至少5秒钟。 最后使用click()函数。 我从中获得了灵感(部分:使用硒) urlpage='' 我的代码如下: driver = webdriver.Firefox

我看了所有类似的问题,但没能解决我的问题。 Selenium似乎找不到一个按钮,我试图在抓取之前点击它来加载更多页面

在下面的图片中是我在做一些sraping(按钮的类名:btn btn default)之前试图点击的按钮,以加载更多

我所做的: 我使用了Selenium的webdriver。 我尝试使用sleep等待页面加载至少5秒钟。 最后使用click()函数。 我从中获得了灵感(部分:使用硒)

urlpage=''

我的代码如下:

 driver = webdriver.Firefox()
driver.get(urlpage)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);var lenOfPage=document.body.scrollHeight;return lenOfPage;")
time.sleep(5)
button = driver.find_element_by_class_name("btn btn-default")
button.click()

如果有人知道我做错了什么,我将不胜感激:)

问题可能来自这样一个事实,即您试图通过提供两个类名(“btn”和“btn默认值”)来查找类名。当我把线路改成

button = driver.find_element_by_class_name("btn-default")
它似乎工作得很好。请注意,类为“btn default”的元素很少,它将只返回第一个元素。您可以使用该函数

find_elements_by_class_name(class_name)

查找此类中的所有元素(将返回一个列表对象)。

感谢您的回复。当我尝试以下操作时:button=driver.find_elements\u by_class_name([“btn-default”])print(button)它响应InvalidSelectorException:给定的css选择器表达式“['btn-default']”无效:语法错误:Document.querySelector所有:“.['btn-default']”无效selector@colla我的错,当我写[类名]我的意思是这样使用它:通过类名称(“btn默认”)查找元素Netanel,我有以下问题:元素ClickInterceptedException:Element在点(488566)处不可单击,因为另一个元素

遮挡了它。你知道如何修复它吗?@colla不确定,但发现了以下两个问题: