0

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.sstatic.net/UvoJf.png

2
  • Can you provide your code Commented Nov 9, 2019 at 21:13
  • Updated the threads code Commented Nov 9, 2019 at 22:25

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the pointer, i tried the code above but nothing happens it still just runs with no error or desired result. Here's the code for the function bot = self.bot bot.find_element_by_class_name('Icon--reply').click() time.sleep(6) filePath = r'F:\Programming\Python\Tweet Bot\Videos\broom.jpg' element = bot.find_element_by_css_selector('input.file-input') bot.execute_script("arguments[0].style.display = 'block';", element) time.sleep(1) element.send_keys(filePath)
@BryanReasonableManAdams I believe there was an error in the locator strategy used. I've updated the locator strategy after looking at the HTML on the page link you provided. Give this a try, and let me know if it works.
Tried it and it still doesn't work i have a hunch that it could be that i have a extension which forces twitter to be the old theme. Its called GoodTwitter. I did this so i could fish out tweet IDs. Here are two screen shots. One of my function and one of the HTML for the button i'm trying to get. i.imgur.com/dpM6kfq.png i.imgur.com/fO9LBVS.png
The locator strategy matches up with the HTML on the page -- not sure why the issue is happening. The extension shouldn't affect this, but it might. Twitter is pretty advanced, so they probably have a lot of their functionality locked down to limit bot activity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.