Assertion for checking the selected option is correct from a dynamic dropdown

 import time


from selenium import webdriver
from selenium.webdriver.chrome.service import Service

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
service_obj = Service("C://Users//ancha//chromedriver_win32(4)//chromedriver.exe")

driver = webdriver.Chrome(service=service_obj, options=chrome_options)

driver.get("https://www.rahulshettyacademy.com/dropdownsPractise/")
driver.find_element(By.ID, "autosuggest").send_keys("ind")
# As the browser takes time to populate the information
time.sleep(2)

countries = driver.find_elements(By.CSS_SELECTOR, "li[class='ui-menu-item'] a")
print(len(countries))
#driver.close()
for country in countries:
if country.text== "India":
country.click()

break

print(driver.find_element(By.ID, "autosuggest").get_attribute("value"))
assert driver.find_element(By.ID, "autosuggest").get_attribute("value") == "India"

driver.close()

Comments

Popular posts from this blog

Getting email id from a child window and paste in parent window to login and catching the error message

For bypassing SSL and for running in headless mode

Assertion to check that the text is not displayed when Hide button is clicked