How to find the path for the tweet textbox while using selenium?
Question:
I can’t find the textbox for tweeting while using the auto software selenium.I have tried multiple class-names,xpaths in and around the textbox.
driver.get("https://twitter.com/home")
twe=driver.find_element(By.XPATH,'//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/div/div[2]/div[1]/div/div/div/div[2]/div[1]/div/div/div/div/div/div[2]/div/div/div/div/label/div[1]/div/div/div/div/div/div/div/div/div/div')
twe.send_keys(f"Happy Birthday")
but=driver.find_element(By.XPATH,'//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/div/div[2]/div[1]/div/div/div/div[2]/div[3]/div/div/div[2]/div/div/span/span')
but.click()
Answers:
See the below code:
driver.get("https://twitter.com/home")
twe = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Tweet text']//span")))
twe.send_keys(f"Happy Birthday")
but = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "(//span[text()='Tweet'])[2]")))
but.click()
I changed the XPATH expressions and used waits
. See if it works.
You will need the below imports:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
I can’t find the textbox for tweeting while using the auto software selenium.I have tried multiple class-names,xpaths in and around the textbox.
driver.get("https://twitter.com/home")
twe=driver.find_element(By.XPATH,'//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/div/div[2]/div[1]/div/div/div/div[2]/div[1]/div/div/div/div/div/div[2]/div/div/div/div/label/div[1]/div/div/div/div/div/div/div/div/div/div')
twe.send_keys(f"Happy Birthday")
but=driver.find_element(By.XPATH,'//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/div/div[2]/div[1]/div/div/div/div[2]/div[3]/div/div/div[2]/div/div/span/span')
but.click()
See the below code:
driver.get("https://twitter.com/home")
twe = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Tweet text']//span")))
twe.send_keys(f"Happy Birthday")
but = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "(//span[text()='Tweet'])[2]")))
but.click()
I changed the XPATH expressions and used waits
. See if it works.
You will need the below imports:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait