At the drinking party, I heard that a colleague at the company created a program that automatically inputs attendance at RPA. So I learned about the existence of selenium from his story and wanted to touch it myself.
I referred to the following site for the introduction.
[Super convenient] Summary of how to automatically operate the browser with Python and Selenium https://tanuhack.com/selenium/
The stumbling block was that I had to match the versions of Google Chrome and chromedriver. As of 12/3, the latest version of Google Chrome is 78, while The latest version of chromedriver was for beta 79. Therefore, it did not work with the latest version of chromedriver, so I downloaded it for 78 again.
I made a program that starts a browser and logs in to the AWS management console.
First, import the module.
aws.py
from selenium import webdriver
Next, I created two functions. send_id specifies the id of the input form in html and enters the key for that input form. id_click specifies the id of the submit button in the html and clicks there.
aws.py
#Enter the key in the id input form
def id_send(id,key):
driver.find_element_by_id(id).send_keys(key)
#Click the id button
def id_click(id):
driver.find_element_by_id(id).click()
Then specify the local chrome driver. The browser that opens is the AWS Management Console.
aws.py
#Specify a local chrome driver
driver = webdriver.Chrome('C:\\Users\\username\\Desktop\\selenium\\chromedriver')
#Open browser
driver.get('https://ap-northeast-1.console.aws.amazon.com/console/home?region=ap-northeast-1#')
In the opened browser, look for information on F12, input form ... (I have no knowledge of html, so I'm groping) ʻId =" resolved_inut "` is like that.
Now, let's use the created function so that you can enter and send the account ID here. The account ID is actually a 12-digit number.
aws.py
#Input and send on the first screen
id_send('resolving_input','Account ID')
id_click('next_button')
Then the account ID is entered ...
I jumped to the next page.
In the same way, find the ID of the user name and password input form and put it in the program.
aws.py
id_send('username','username')
id_send('password','password')
id_click('signin_button')
And when it was sent successfully, I was able to log in.
The above is this program.
This time it was a simple login like this, but if you learn more about html, css, javascript, I felt that the range of automation would expand. I want to deepen my knowledge while trying to create my own site.
Recommended Posts