- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to input letters in capital letters in an edit box in Selenium with python?
We can input letters in capital letters in an edit box in Selenium with the help of Action Chains class. These classes are generally used for automating interactions like context menu click, mouse button actions, key press and mouse movements.
These types of actions are mainly common in complex scenarios like drag and drop and hovering over an element on the page. The methods of the Action Chains class are utilized by advanced scripts. We can manipulate DOM with the help of Action Chains in Selenium.
The action chain object implements the ActionChains in the form of a queue and then executes the perform() method. On calling the method perform(), all the actions on action chains will be performed.
The method of creating an Action Chain object is listed below −
First we need to import the Action Chain class and then the driver will be passed as an argument to it.
Now all the operations of action chains can be done with the help of this object.
Syntax
Syntax for creating an object of Action Chains −
from selenium import webdriver
# import Action chains from selenium.webdriver import ActionChains # create webdriver object driver = webdriver.Firefox() # create action chain object action = ActionChains(driver)
After creating an object of Action Chains, we can perform numerous operations one by one like a chain which is queued.
In order to enter letters in upper case in the edit box, we need to first move to the edit box, then perform click() action. Then press SHIFT and enter the letters using send_keys() method. Finally use perform() to execute all these queued operations.
Syntax
#element source = driver.find_element_by_id("name") #action chain object action = ActionChains(driver) # move the mouse to the element action.move_to_element(source) # perform click operation on the edit box action.click() # perform clicking on SHIFT button action.key_down(Keys.SHIFT) # input letters in the edit box action.send_keys('tutorialspoint') # perform the queued operation action.perform()
Example
Code Implementation for inputting letters in upper case.
from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() # identifying the source element source= driver.find_element_by_xpath("//input[@name='search']"); # action chain object creation action = ActionChains(driver) # move the mouse to the element action.move_to_element(source) # perform click operation on the edit box action.click() # perform clicking on SHIFT button action.key_down(Keys.SHIFT) # input letters in the edit box action.send_keys('tutorialspoint') # perform the queued operation action.perform() #to close the browser driver.close()
- Related Articles
- How to enter values in an edit box in Selenium with python?
- How to find capital letters with Regex in MySQL?
- Regex in Python to put spaces between words starting with capital letters
- How to press ENTER inside an edit box in Selenium?
- How to reset or clear an edit box in Selenium?
- How to set the font to be displayed in small capital letters with JavaScript?
- How to key in values in input text box with Javascript executor in Selenium with python?
- c# Put spaces between words starting with capital letters
- How to get the value of the edit box in Selenium?
- Reverse Only Letters in Python
- How to move all capital letters to the beginning of the string in JavaScript?
- How do you enter text in the edit box in Selenium?
- Get value of an input box using Selenium (Python)
- How to convert lowercase letters in string to uppercase in Python?
- How to generate random strings with upper case letters and digits in Python?
