textbar = driver.find_element("xpath",'//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]/p')
while(True):
message = input("Please enter the text you want to send to the selected person to stop the program type -exit- : ")
textbar.send_keys(message)
if(message == "exit"):
break
textbar.send_keys(Keys.RETURN)
CodePudding user response:
In your code, you're calling textbar.send_keys(message)
before checking if the message is exit
. You should move up your if
statement so that you exit the program sooner. And put the find_element
inside the loop to avoid StaleElementReferenceException
. Eg:
while(True):
message = input("Please enter the text you want to send to the selected person. To stop the program, type -exit- : ")
if(message == "exit"):
break
textbar = driver.find_element("xpath",'//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]/p')
textbar.send_keys(message)
textbar.send_keys(Keys.RETURN)