简体   繁体   English

如何使用长下拉列表中的selenium单击元素?

[英]How do i click an element using selenium from a long drop down list?

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! 我试图点击一个元素,让我们从下拉列表中说出一个国家列表,但我只能点击前几个国家使用xpath,当我尝试点击最后一个国家时,似乎点击不工作。这里是代码(它适用于前几个国家,但我想点击下拉列表中的最后一个国家)如果有人帮助我,将不胜感激!

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() 

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() 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何单击使用 Selenium 隐藏的下拉菜单? - How do I click on a drop down menu that is hidden using Selenium? Python - 如何使用 selenium 从消失的下拉列表中查找元素 - Python - How to find an element from a disappearing drop down using selenium 如何使用 python 从 selenium webdriver 的下拉列表中选择一个值? - How do I select a value from drop down in selenium webdriver using python? 单击使用硒的下拉列表中的所有值 - Click all values in a drop down list using selenium 单击硒下拉菜单中的选定元素 - click on selected element in drop down menu with selenium 如何使用Python和Selenium点击页面上的多个下拉列表? - How can I click on multiple drop down list on a page with Python and Selenium? Python Selenium:如何使用CSS选择器单击下拉菜单中的链接? - Python Selenium: How do I click a link in a drop down menu with css selector? 如何使用Selenium和Chrome单击Python中的下拉菜单 - How to click on drop down menu in Python using Selenium and Chrome 如何使用 selenium webdriver python 单击呼叫下拉列表? - How to click the call drop down using selenium webdriver python? 将 Playwright 用于 Python,如何从下拉列表中选择一个选项 select? - Using Playwright for Python, how do I select an option from a drop down list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM