Click here for see the codeI'm learning python, but I don't know how to select this part, anyone help me?
I tried to select the cell with xpath and put the country but I don't know how to select it to assign the value
test = driver.find_element_by_xpath("//input[@type='search']")
test.send_keys('United States')
test.click()
CodePudding user response:
What you want to do is to select the list item.
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Firefox()
driver.get('url')
select = Select(driver.find_element_by_xpath("//input[@type='search']"))
# select by visible text
select.select_by_visible_text('United States')
# select by value
select.select_by_value('3')
Link to original answer](How to select a drop-down menu value with Selenium using Python?).
CodePudding user response:
Try this.
# Assuming this this the correct xpath to the search bar
test = driver.find_element_by_xpath("//input[@type='search']")
test.click()
driver.find_elements_by_xpath("//li[contains(text(), 'United States') and @class='up-menu-item']").click()