0

I'm looking to loop through these integers, inputting each into a web browsers textbox. I've already set up the python code to open chrome, navigate to the site, login, and navigate to the text box (unfortunately it's at work - I can reattach it here tomorrow morning), but how do I get it to take the first user input from below, type it into the textbox - let's pretend its find_element_by_id('thetextbox') - I'll get it to press the enter button at the bottom of the page here, but then navigate back to the same textbox as before and enter the second user input? And then how would it know to stop at however many integers were inputted?

Sorry if it's a bit confusing, I really should have sent the code to myself :(

x = raw_input("Enter list of integers separated by a space:")
integers = [int(i) for i in x.split()]
2
  • you can also use class name, if its unique or if you can input any static class to it and then try to access that with selenium.getAttribute(//xpath@class); might help Commented Jan 6, 2020 at 20:30
  • As you say you need a loop. Using a for loop over your integers array is a good place to start. Commented Jan 6, 2020 at 20:35

2 Answers 2

1

Given the info above you can do:

x = raw_input("Enter list of integers separated by a space:")
integers = [int(i) for i in x.split()]

for i in integers:
  driver.find_element_by_id('thetextbox').send_keys(i)
Sign up to request clarification or add additional context in comments.

Comments

0

Using the code sample from the selenium documentation:

You'll need probably need to wrap the loop around your get, find, and send_keys methods.

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys

    driver = webdriver.Firefox()
    x = raw_input("Enter list of integers separated by a space:")
    for i in input.split():
        driver.get("http://www.python.org")
        assert "Python" in driver.title
        elem = driver.find_element_by_name("q")
        elem.clear()
        elem.send_keys(i)
        elem.send_keys(Keys.RETURN)
   driver.close()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.