Home > Mobile >  How to select an element in list box by selenium in python
How to select an element in list box by selenium in python

Time:08-17

I am totally new in python. I want to select an element in list box. I know it is such an easy task but I don't know why it is not working on my computer. The URL is:

https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul

how can I choose one of them with with select?

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome('C:\Webdriver\chromedriver.exe')
driver.get('https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul')
time.sleep(2)

I try a lot to select by:

select.select_by_visible_text("Partner country/ Country Groups")

or

driver.find_element(By.XPATH,'//*[@id="yXAPg2-cave"]').click()

But it does not work! I don't know why! May you help me?

CodePudding user response:

You can click the desired element by selecting the element on the text it contains. The following code should work fine.

element = driver.find_element(by=By.XPATH,value='//*[contains(text(), "Partner country/ Country Groups")]')                                                                                                            
element.click()
  • Related