This article uses Python 3.6.0 and Selenium 3.4.0 (WebDriver is Google Chrome).
I had a hard time getting and setting the drop-down menu, so I will leave a note.
select.html
<select name=”color”>
<option value=”red”>Red</option>
<option value=”blue”>Blue</option>
<option value=”green”>Green</option>
</select>
Suppose you have a drop-down menu that says.
Select.py
#Call a function to change to an element that can be handled by the Select tag
from selenium.webdriver.support.ui import Select
#Get the element normally
color_element = browser.find_element_by_name('color')
#Change the acquired element to the element corresponding to the Select tag
color_select_element = Select(color_element)
#Specify the value you want to select
color_select_element.select_by_value('blue')
If you write like this, "blue" will be selected.
At first I couldn't set the value with send_keys and I was really into it, I never thought I had to cast (?). Other than that, the tag needs to be done like this. I have no plans to do anything at the moment, but automation is fun.
Recommended Posts