Unable to upload a pdf file using send_keys or requests

后端 未结 2 1253
面向向阳花
面向向阳花 2021-01-14 05:27

I\'ve written a script in python using selenium to log in to a website and then go on to the target page in order to upload a pdf file. The script can log in successfully bu

2条回答
  •  生来不讨喜
    2021-01-14 06:08

    Please refer below solution to avoid your exception,

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait as Wait
    from selenium.webdriver.common.action_chains import ActionChains
    import os
    
    
    landing_page = 'https://jobs.allianz.com/sap/bc/bsp/sap/zhcmx_erc_ui_ex/desktop.html#/SEARCH/RESULTS/'
    target_link = 'https://jobs.allianz.com/sap/bc/bsp/sap/zhcmx_erc_ui_ex/desktop.html#/APPLICATION/57262231/2/'
    
    driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
    wait = WebDriverWait(driver,30)
    
    driver.get(landing_page)
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,".profileContainer > button.trigger"))).click()
    wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"input[name='alias']"))).send_keys("SIM.iqbal_123")
    wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"input[name='password']"))).send_keys("SShift_123")
    wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"button.loginBtn"))).click()
    
    driver.get(target_link)
    driver.maximize_window()
    button = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"button[class*='uploadBtn']")))
    driver.execute_script("arguments[0].click();",button)
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    element = wait.until(EC.element_to_be_clickable((By.XPATH,"//label[@class='button uploadType-12-btn']")))
    print element.text
    webdriver.ActionChains(driver).move_to_element(element).click(element).perform()
    webdriver.ActionChains(driver).move_to_element(element).click(element).perform()
    absolute_file_path = os.path.abspath("Path of your pdf file")
    
    print absolute_file_path
    file_input = driver.find_element_by_id("DOCUMENTS--fileElem")
    file_input.send_keys(absolute_file_path)
    

    Output:

提交回复
热议问题