Reputation: 1620
I'm trying to click on a element let's say a list of countries from a drop down list, but i'm able to click only first few countries using xpath, when i try to click the last country seems the click not working.Here is the code(it works for first few countries but i want to click the last country from the drop down list) If someone help me that would be appreciated!
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
import time
driver = webdriver.Chrome()
driver.get('https://www.example.com/dropdown')
##click accept cookies button
wait(driver, 5).until(EC.visibility_of_element_located(
(By.XPATH, '//div[@class="cookie-button-wrapper"]'))).click()
##time delay
time.sleep(20)
##click on specific country from the dropdown
wait(driver, 5).until(EC.visibility_of_element_located(
(By.XPATH, '//div[@class="tv-dropdown__button tv-dropdown-behavior__button tv-screener-market-select__button js-screener-market-button apply-common-tooltip common-tooltip-fixed"]'))).click()
wait(driver, 5).until(EC.visibility_of_element_located(
(By.XPATH, '//*[@data-market="argentina"]'))).click()
Upvotes: 5
Views: 8550
Reputation: 106
First try to scroll till element:
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_xpath("//*[@data-market='italy']")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
Then try to click on it, using the last part of your code:
wait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, '//*[@data-market="italy"]'))).click()
Upvotes: 7