如何使用 Selenium 和 Python 从 https://www.aliexpress.com/运送到下拉菜单中选择一个国家 [英] How to select a country from https://www.aliexpress.com/ ship to drowdown menu using Selenium and Python
本文介绍了如何使用 Selenium 和 Python 从 https://www.aliexpress.com/运送到下拉菜单中选择一个国家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在网站
On the website https://www.aliexpress.com, I need to change the country from the dropdown menu using selenium
<span class="ship-to">
I can't find how I click on the country value using selenium
解决方案
From the Ship to drop-down-menu to select the country as Afghanistan you have to induce WebDriverWait for the element_to_be_clickable()
and you can use the following xpath based Locator Strategies:
Code Block:
driver.get("https://www.aliexpress.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@class, 'switcher-info')]/span[@class='ship-to']/i"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='address-select-trigger']//span[@class='css_flag css_in']//span[@class='shipping-text']"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='address-select-item ']//span[@class='shipping-text' and text()='Afghanistan']"))).click()
Note : You have to add the following imports:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
这篇关于如何使用 Selenium 和 Python 从 https://www.aliexpress.com/运送到下拉菜单中选择一个国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文