'Python Selenium Retweet Twitter

import selenium.webdriver 
driver = selenium.webdriver.Firefox()
driver.get("https://twitter.com/login")
driver.find_element_by_css_selector(".js-username-field").send_keys("username")
driver.find_element_by_css_selector(".js-password-field").send_keys("password")
driver.find_element_by_css_selector("#page-container > div > div.signin-wrapper > form > div.clearfix > button").click()
driver.get("https://twitter.com/DisbeArex")

How do I retweet the most recent tweet using Selenium and Python? I know how to use it with the api, but when I try with Selenium i get errors



Solution 1:[1]

I would do something like this:

a = driver.find_element_by_class('IconContainer')

....for i in a:
......a.click(0)

I think this should work.

Solution 2:[2]

To retweet on the first tweet

ret = 'section.css-1dbjc4n > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > article:nth-child(1) > div:nth-child(2) > div:nth-child(2) > div:nth-child(2) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > svg:nth-child(2)'

Found element and click

driver.find_element_by_css_selector(ret).click()

Confirm retweet

driver.find_element_by_css_selector("div.r-1j3t67a:nth-child(1)").click()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 General Grievance