I can not detect xpath on Twitter

0

Since yesterday I have been trying in Python, with Selenium, to create a bot that allows voting a poll. The process from the beginning of the session until the vote is done perfectly, but when I indicate the xPath of the option to vote, it does not detect it and the bot is closed. I tried to externalize the frame in another tab, but on the one hand we have the same error, and on the other, it seems that the survey works by Tokens, that is, even if it is accessed from the same user, the link to the frame expires when close and open again.

I leave the extract of the code where I miss the error in case someone can light me a little. Greetings.

#Bot entra a encuesta

#entrar encuesta
driver.get("https://twitter.com/majeflomon/status/988357553007550465")
print("----Accediendo a encuesta")

time.sleep(2)

#votar encuesta
button_opc = driver.find_element_by_xpath("/html/body/div/div/div/div/div[2]/label/span[2]")
button_opc.click()
print("----Opcion Marcada (NO)")

#enviar voto
button_env = driver.find_element_by_xpath("/html/body/div/div/div/div/div[4]/div/span[1]")
button_env.click()
print("----Votacion Realizada")
    
asked by Manuel Jesus Flores 24.04.2018 в 09:42
source

1 answer

1

Looking for surveys from that same user, I have seen that the surveys are about an iframe. Therefore, you must first change the iframe that contains the survey:

driver.switch_to.frame("id") 
# Tambien se puede cambiar al iframe por el name
# O pasando una variable de tipo WebElement, localizandola
# previamente por xpath

...

# Una vez realizada la votacion debes volver al contenido principal
# es decir, salir del iframe
driver.switch_to_default_content()
    
answered by 26.04.2018 в 08:08