0

I am trying to use selenium to grab the line of a text file, input that line into an element, click the submit option, and continue to do every line in the txt file until it is done. What I have tried is only pasting in the entire text file which is not what I want. The element I will be sending the keys to is below.

newalias = driver.find_element_by_id('mailbox_alias_source')

I hope this makes sense and you guys can help, Thanks!

ropexlol
  • 3
  • 3
  • Use newalias.send_keys(lineoftext) after that. What part did you need help with? – Arundeep Chohan Sep 26 '20 at 23:51
  • i needed help with grabbing the first line of text in the txt file, then having it type it in to the element, then I want it to automatically continue that process for every line of the text file until it completes. – ropexlol Sep 26 '20 at 23:54
  • Does the page reload at all? After the submit. – Arundeep Chohan Sep 26 '20 at 23:57
  • I haven't gotten that far yet. I'm still trying to read the contents of the text file and have it type in each line, and click the submit button 1 by 1. When I manually type something in and click submit, yes the page refreshes. – ropexlol Sep 27 '20 at 00:00
  • You might need some waits after the submits to get the element again. – Arundeep Chohan Sep 27 '20 at 00:22

1 Answers1

0

Would be a start.

file = open ("data.txt", "r")
lines = file.readlines()
for line in lines:
    newalias = driver.find_element_by_id('mailbox_alias_source')
    newalias.send_keys(line.strip())  
file.close()
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32
  • this actually seems to be going in the right direction. When I click the create button, there are 2 elements that have a chance of coming up and depending on which one it is decides what I need the script to do next. How can I make an if statement that includes both elements and will do something different for both? thank you for helping, I'm new to python, just trying to learn a little. Have a good day. – ropexlol Sep 27 '20 at 00:25
  • I am trying to get it to clear the textbox if it is wrong, and I can't get it to work. I have tried this: – ropexlol Sep 27 '20 at 00:33
  • it looks weird when I paste it in here so I put it in a pastebin. https://pastebin.com/ASvJUQKA – ropexlol Sep 27 '20 at 00:35
  • https://stackoverflow.com/questions/9567069/checking-if-element-exists-with-python-selenium look at this for checking if element exists. – Arundeep Chohan Sep 27 '20 at 00:36
  • here is the error I get: https://pastebin.com/Wz2QJ3RR – ropexlol Sep 27 '20 at 00:36
  • https://stackoverflow.com/questions/47993443/selenium-selenium-common-exceptions-nosuchelementexception-when-using-chrome for that error, – Arundeep Chohan Sep 27 '20 at 00:42
  • Ok, I got a lot working. I am now trying to make it so when this element exists, it sends a message of the data that worked, to a discord webhook. An example would be if it tries "goodemail" and it works, the element exists, and i want it to send to the webhook "goodemail is successful" if that makes sense. How would I do this? I believe the checking if an element exist is working, I am using css for that. Thanks for the help again. – ropexlol Sep 27 '20 at 01:30
  • Might want to add another question with all your code and vote this answer. – Arundeep Chohan Sep 27 '20 at 01:48
  • ok I made it, thanks again for helping. Means a lot. – ropexlol Sep 27 '20 at 02:00