简体   繁体   English

如何使用 selenium webdriver python 单击呼叫下拉列表?

[英]How to click the call drop down using selenium webdriver python?

I am not able to click the call dropdown using xpath or css selector and scrape the phone numbers.Is there any way to do so?我无法使用 xpath 或 css 选择器单击呼叫下拉列表并抓取电话号码。有什么办法吗?

driver=set_options_driver(headless=False)
driver.get('https://www.yellowpages.ca/bus/Ontario/Maidstone/CSR-Coxon-s-Sales-Rentals-Ltd/7222758.html?what=Rajic-Holdings-Inc&where=Maidstone+ON&useContext=true')
yp_name=[k.text for k in driver.find_elements_by_xpath("//div[@class='merchant__info--root ']//div[@class='merchant__name']")]
yp_addr=[k.text for k in driver.find_elements_by_xpath("//div[@class='merchant__info--root ']//div[@class='merchant__item merchant__address merchant__address__mobile']")]
try:
    #driver.find_element_by_xpath("//div[@class='merchant__info-content']//span[@class='ypicon ypicon-phone mlr__icon']").click()
    driver.find_element_by_xpath("//ul[@class='mlr mlr--merchant']//span[@class='ypicon ypicon-phone mlr__icon']").click()
    yp_phone=driver.find_element_by_xpath("//li[@class='mlr__item mlr__item--more mlr__item--phone mlr__item--active isActive']//span[@class='mlr__sub-text']").text
except:
    yp_phone=" "

您可以尝试单击如下所示的锚标记,而不是单击 span 元素。

driver.find_element_by_xpath("//ul[@class='mlr mlr--merchant']/li/a").click

To click on the element with text as Call associated with the dropdown you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:要单击带有文本作为与下拉列表关联的Call的元素,您必须诱导WebDriverWait以使元素可点击,您可以使用以下任一解决方案:

  • Using CSS_SELECTOR :使用CSS_SELECTOR

     driver.get("https://www.yellowpages.ca/bus/Ontario/Maidstone/CSR-Coxon-s-Sales-Rentals-Ltd/7222758.html?what=Rajic-Holdings-Inc&where=Maidstone+ON&useContext=true") WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.merchant__info--root span.ypicon.ypicon-phone.mlr__icon"))).click()
  • Using XPATH :使用XPATH

     driver.get("https://www.yellowpages.ca/bus/Ontario/Maidstone/CSR-Coxon-s-Sales-Rentals-Ltd/7222758.html?what=Rajic-Holdings-Inc&where=Maidstone+ON&useContext=true") WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='merchant__info--root ']//span[@class='ypicon ypicon-phone mlr__icon']"))).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:浏览器快照:

黄页

暂无
暂无

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

相关问题 如何使用Selenium和Chrome单击Python中的下拉菜单 - How to click on drop down menu in Python using Selenium and Chrome 使用Selenium Webdriver从python的下拉列表中选择选项 - Selecting options from drop down list in python using Selenium Webdriver 如何使用带有 Python 的 Selenium Webdriver 抓取下拉菜单选项? - How to scrape drop-down menu options using Selenium Webdriver with Python? 如何使用python或java在selenium webdriver中选择kendo-drop - how to select kendo-drop down in selenium webdriver using python or java 如何使用 python 从 selenium webdriver 的下拉列表中选择一个值? - How do I select a value from drop down in selenium webdriver using python? 如何使用带有Python的Selenium Webdriver从ul li下拉列表中获取所有选项? - How to get all options from ul li drop-down using Selenium Webdriver with Python? 如何使用 select 这个非 select 下拉菜单中的元素使用 Selenium Webdriver 和 ZA7F57F35426B9387411 - How to select this element from this non select drop-down menu using Selenium Webdriver and Python 如何使用Selenium WebDriver从下拉框中选择 - How to select from drop down box using selenium webdriver 无法在下拉列表中向下导航,使用Python在Selenium webdriver中使用keys.ARROW_DOWN - unable to navigate down in a drop down list , using keys.ARROW_DOWN in Selenium webdriver using Python 使用 selenium Python 库单击下拉菜单中的项目 - Click an item in a drop-down menu using selenium Python library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM