Ashish Sharma
Ashish Sharma

Reputation: 1

how to select element from dropdown/address list API

import select from selenium.webdriver.support.select import Select

from selenium import webdriver import time from selenium.webdriver.chrome.service import Service s=Service("C:\Drivers\chromedriver_win32\chromedriver.exe") #excutable service patch driver = webdriver.Chrome(service=s)

driver.maximize_window() driver.get("https://app.mondofi.co/")

driver.find_element("xpath", '//[@id="root"]/div/div/form/div[1]/div/input').send_keys("stage_mondofi") #print(type(userEle)) driver.find_element("xpath", '//[@id="root"]/div/div/form/div[2]/div/input').send_keys("Z3Pytzsh56eQSZmH")

driver.find_element("xpath", '//[@id="root"]/div/div/form/div[3]/button').click() time.sleep(2) driver.find_element("xpath", '//[@id="root"]/div/div[3]/div[1]/div/div[2]/div/div[2]/ul/li[3]/a').click() driver.find_element("xpath", '//[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[2]/div/div/input').send_keys("Ash") driver.find_element("xpath", '//[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[3]/div/div/input').send_keys("Ish") driver.find_element("xpath", '//[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[4]/div/div/input').send_keys("[email protected]") driver.find_element("xpath", '//[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[5]/div/div/input').send_keys(9418035364) driver.find_element("xpath", '//[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[6]/div/div/input').send_keys("Lake View") driver.find_element("xpath", '//[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[7]/div/div[1]/input').send_keys("Lake") driver.find_element("xpath", '//*[@id="root"]/div/div[2]/div/div/div[2]/div/div/form/div/div[9]/div/div/div[1]/input').send_keys("Surrey") select.select('Surrey, BC, Canada')

Upvotes: 0

Views: 80

Answers (1)

anon
anon

Reputation:

You should use the selenium select class

for example:

from selenium import webdriver
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome(service=s)
driver.get('url')

select = Select(driver.find_element_by_id(select_id))

# select by visible text
select.select_by_visible_text(write the items to appear)

# select by value 
select.select_by_value(item value)

if using xpath:

driver.find_element_by_xpath("//select[@name='element_name']/option[text()='option_text']").click()

Upvotes: 0

Related Questions