Working with Input box/Test Box in Selenium with Python

Selenium is an effective device for controlling an internet browser thru the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python.

Requirement: You need to install chromedriver and set path. Click here to download, for more information follows this link.

Working with Input box/Test Box, let us how to:

  1. find how many input boxes present in the web page.
  2. provide value into text boxes.
  3. get the status.

Process:

  • Importing the modules.
  • https://write.geeksforgeeks.org/reviewer-copy/2197543
  • We will load the URL https://gitpress.io/u/1155/selenium-Example2RadioButtonAndCheckBoxes in the driver.
  • Now select the XPath of the desired field by doing:



  • Then find(navigate) the class name where input is present.
  • Find the length using len().
  • Check the status by is_displayed().

Implementation:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the modules
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
  
# using chrome driver
driver = webdriver.Chrome()
  
# web page url
  
# select class name where is input box are present
element = driver.find_elements(By.CLASS_NAME, "text_field")
  
# find number of input box 
print(len(element))
  
# fill value in input box
driver.find_element_by_xpath('//*[@id="RESULT_TextField-1"]').send_keys("praveen")
driver.find_element_by_xpath('//*[@id="RESULT_TextField-2"]').send_keys("yadav")
driver.find_element_by_xpath('//*[@id="RESULT_TextField-3"]').send_keys("87871111")
  
# check status
x = driver.find_element_by_xpath('//*[@id="RESULT_TextField-1"]').is_displayed()
print(x)
driver.close()

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.