I'm trying to select the first value of a list (北京 in this case) from the website: https://search.jd.com/Search?keyword=%E5%AE%A0%E7%89%A9%E9%A3%9F%E5%93%81&qrst=1&wq=%E5%AE%A0%E7%89%A9%E9%A3%9F%E5%93%81&stock=1&page=5&s=121&click=1
The xpath is:
//*[@id="ttbar-mycity"]/div[2]/div[2]/div/div/div[1]/a
My code is:
browser.find_element_by_xpath("//ul[@id='ttbar-mycity']/div[2]/div[2]/div/div/div[1]/a[.= '北京']").click()
But it throws a "No such element exception"
UPDATE: this is the full code so far (thanks DebanjanB):
browser.get("https://global.jd.com/")
browser.find_element_by_id("key").send_keys(mysearch)
browser.find_element_by_id("search-btn").click()
wait.until(EC.title_contains(mysearch))
ActionChains(browser).move_to_element(WebDriverWait(browser, 50).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='ui-areamini-text' and @title='北京']")))).perform()
WebDriverWait(browser, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='dd dorpdown-layer']//div[@class='ui-areamini-content-list clearfix']/div/a"))).click()
It throws a TimeoutException at the line
ActionChains(browser).move_to_element(WebDriverWait(browser, 50).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='ui-areamini-text' and @title='北京']")))).perform()