简体   繁体   中英

How to fix Upload image to twitter with Selenium (Python)

Currently i am trying to upload a image to Twitter for my reply bot. The current code i have gives no errors but it also doesn't attach the image. I've tried many approaches but i can't get it. Here is my current code.

    bot = self.bot
    bot.find_element_by_class_name('Icon--reply').click()
    time.sleep(6) 
    bot.find_element_by_css_selector('input.file-input').send_keys(r'F:\Programming\Python\Tweet Bot\Videos\broom.jpg')

Here's a screenshot of the tweet i am using this snippet of code on. https://i.imgur.com/RrtMnDd.png

You probably need to execute JavaScript on the file input element to reveal it before you can send keys to it.

element = bot.find_element_by_xpath("//input[@type='file']")

bot.execute_script("arguments[0].style.display = 'block';", element)

element.send_keys(filePath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM