【问题标题】:how to click in selenium and downloadfile如何点击 selenium 和下载文件
【发布时间】:2022-01-19 10:42:03
【问题描述】:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
    
    options = webdriver.ChromeOptions() 
    options.add_experimental_option("excludeSwitches", ["enable-logging"])
    driver = webdriver.Chrome(options=options, executable_path=r'C:/Users/u/Desktop/python/pythonfile/chromedriver.exe')
    
    driver.get('https://www.plfil.com/actordetail/163964632064582')
    #driver.find_element_by_css_selector('#root > div > div.actorProfileSectionDiv > div.floatDivBorder > div > div:nth-child(4) > div:nth-child(2) > a').click()
    #driver.find_element_by_xpath('//*[@id="root"]/div/div[2]/div[3]/div/div[3]/div[1]/a/div/div').click()
    #driver.find_element_by_css_selector('#root > div > div.actorProfileSectionDiv > div.floatDivBorder > div > div:nth-child(4) > div:nth-child(2) > a').click()
    #driver.find_element_by_css_selector('#root > div > div.actorProfileSectionDiv > div.floatDivBorder > div > div:nth-child(4) > div:nth-child(2)').click()
    #driver.find_element_by_class_name('div.PlfilButton'[0]).click()

我想点击 pdf 下载按钮,但我不能。我该怎么做?**

【问题讨论】:

  • 访问所需元素需要哪些手动步骤?你看到什么错误?使用相关元素 HTML 和错误堆栈跟踪更新问题。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python selenium web-crawler


【解决方案1】:

您需要知道该下载按钮的 XPATH。为此,右键单击该元素顶部并单击检查,再次右键单击检查,它将指向要查看 html 代码中的哪一行。在此之后右键单击有问题的行,然后单击复制 xpath。之后,在以下位置实现:

import time

time.sleep(1) # just to make sure the page loads
driver.find_element(By.XPATH, "insert xpath here").click()

请注意,find_element_by_xxxxxx 已弃用,应改为使用 find_element(By.xxxx, '')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-28
    • 2020-05-04
    • 1970-01-01
    • 2020-07-30
    • 2022-07-23
    • 1970-01-01
    • 2018-11-20
    • 2015-03-21
    相关资源
    最近更新 更多