A web browser test tool called selenium, Roughly speaking, I knew that there was something that could automatically operate the web screen by writing a little code. I wanted to try it for the time being.
I borrowed a lot of wisdom from my ancestors, but I made a note because there were some stumbling points.
It will be similar to sutra copying, but the basics are Introduction to Selenium starting with just 3 lines of python Keep a record of where you stumbled along. (As of September 10, 2020)
On the browser screen using selenium Automatically display search results for the character string "raccoon dog image"
Install homebrew
Install python
The above is described in Reference article.
$ brew install chromedriver
#I couldn't install it above, so I tried this as the error statement says.
$ brew cask install chromedriver
$ pip install selenium
test.py
from selenium import webdriver
driver = webdriver.Chrome("chromedriver path")
driver.get("https://google.co.jp")
The chromedriver path can be found with which chromedriver
$ python test.py
I got an error in the pop-up here, so I gave permission to execute the downloaded application by referring to the following.
This should open your chrome web browser.
If you can do it so far, write the following
test.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys #add to
driver = webdriver.Chrome("/usr/local/bin/chromedriver")
driver.get("https://google.co.jp")
text = driver.find_element_by_name("q") #Specify the name attribute of the search box
text.send_keys("Raccoon image")#String"Raccoon image"In the text box
text.send_keys(Keys.ENTER) #Press ENTER Use a special key
→ I decided to specify the name attribute
→ I set it to press ENTER (instead of searching for and clicking the search button) [^ 1]
error contents
:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I couldn't investigate why such an error occurred, but For the time being, the web browser opens automatically and characters are entered in the search box without permission. I was able to reach the point where the search results are displayed.
[^ 1]: From selenium quick reference
Recommended Posts