Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.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_Beautifulsoup - Fatal编程技术网

Python Selenium-如何单击非按钮元素

Python Selenium-如何单击非按钮元素,python,selenium,beautifulsoup,Python,Selenium,Beautifulsoup,我一直试图点击按钮,但没有成功(如下图所示)。 我甚至不能得到我想要点击的元素。 如果有人能帮我找到元素以及如何单击它,这将对我非常有帮助。 提前谢谢。 首先,您需要等待元素出现在页面上,然后滚动到该元素,然后单击它。 我试着按如下方式做: from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.suppo

我一直试图点击按钮,但没有成功(如下图所示)。 我甚至不能得到我想要点击的元素。 如果有人能帮我找到元素以及如何单击它,这将对我非常有帮助。 提前谢谢。

首先,您需要等待元素出现在页面上,然后滚动到该元素,然后单击它。
我试着按如下方式做:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

pagination_2_el_xpath = '//li[@class="ant-pagination-item ant-pagination-item-2"]'

pagination_2_el = wait.until(EC.presence_of_element_located((By.XPATH, pagination_2_el_xpath)))

time.sleep(0.1)

actions = ActionChains(driver)
actions.move_to_element(pagination_2_el).perform()

pagination_2_el.click()
此外,最好单击“下一页”按钮,以便您可以使用:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

next_page_css = 'li.ant-pagination-next'

next_page = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, next_page_css)))

time.sleep(0.1)

actions = ActionChains(driver)
actions.move_to_element(next_page).perform()

next_page.click()

你能分享一下你迄今为止的尝试吗?你有什么错误吗?非常感谢它成功了!,我还有一个问题,当我尝试使用soup.find.all获取第二页的元素时,在我单击“下一页”按钮后,它仍然会提供第一页的元素。为什么?首先,既然我回答了问题,请接受答案。正如你现在提到的,你有一些新问题,所以你应该为此提出一个新问题。在这里,每个问题都应该问一个特定的问题。否则版主将关闭。当你问新问题时,请提供更多信息:你到底尝试了什么,错误是什么等。哦,对不起,我的不好。谢谢,没问题。我只是想帮你。正如你所看到的,这个问题已经结束了,因为你没有在你的问题中提供足够的最低限度的信息。