【问题标题】:How to upload a file on hk.jobdb.com by selenium, python?如何通过 selenium、python 在 hk.jobdb.com 上上传文件?
【发布时间】:2021-01-04 06:52:47
【问题描述】:

详情: 我已经使用 id & 'xpath' 尝试了下面的代码,并在输入标签处添加了带有 'block' 的显示块状态。但它仍然无法在页面上附加任何 pdf 文件。

URL = "https://hk.jobsdb.com/hk/en/Job/NonMemberApplication?jobAdIdList=100003008140517&pass=true&trackData=%7B%22ApplySource%22%3A1%7D&token=0~8e61b1eb-cfc1-4de7-bb5a-706976405da2&sectionRank=1"

driver.get(URL)
time.sleep(3)

container = driver.find_element_by_name("userfile")
driver.execute_script("arguments[0].style.display':' 'block';", container)
input = driver.find_element_by_id('UploadButtonc_NnMrAnItD3p_AhRe0')
input.send_keys('file path')
time.sleep(1)[enter image description here][1]
driver.close()

错误信息

selenium.common.exceptions.JavascriptException Messagejavascript 错误 Unexpected token ':'

Thanks

【问题讨论】:

    标签: python selenium upload


    【解决方案1】:
    input = driver.find_element_by_xpath('//input[@name="userfile"]')
    input.send_keys('file path')
    

    你应该将文件发送到输入标签而不是按钮,也应该删除

    driver.execute_script("arguments[0].style.display':' 'block';", container)
    

    【讨论】:

    • 我也尝试编写如下代码,但它会有另一个错误消息“selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable” : input = driver.find_element_by_id('// *[@id="UploadButtonc_NnMrAnItD3p_AhRe0"]') input.send_keys('文件路径')
    • 你看到答案中的代码了吗?请添加您使用的新代码
    • 亲爱的 PHDide,是的,我确实已经尝试过您的代码。顺便说一句,我点击的是“申请成为非会员”,上传按钮在下面的页面:hk.jobsdb.com/hk/en/Job/… 然后,我尝试了你的代码,但失败了....请帮助非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2018-03-09
    • 2015-09-14
    • 2018-11-01
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    相关资源
    最近更新 更多