Search code examples
selenium-webdriverxpathcss-selectors

How to find the find the div data element using Selenium web driver and Python


enter image description here

I need to select "Australia" from this list using Selenium web driver, Python. And I have tried XPath and CSS selector but could not properly locate the element.

driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div/div[2]/div[2]/div[2]/div[1]").click()
driver.find_element(By.CSS_SELECTOR,"div[@data-v-9d5976ee='Australia']").click()

Please instruct how can i locate the element? what type of locator should be used here to select the value i want from the list


Solution

  • Use this XPath:

    driver.find_element(By.XPATH, '//div[text()="Austria"]')
    

    or

    driver.find_element(By.XPATH, '//div["Austria"]')