Как щелкнуть выпадающий вызов с помощью python Selen Webdriver? - PullRequest
1 голос
/ 01 июля 2019

Я не могу щелкнуть раскрывающийся список вызовов с помощью селектора 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=" "

Ответы [ 2 ]

1 голос
/ 01 июля 2019

Чтобы щелкнуть элемент с текстом Вызвать , связанный с раскрывающимся списком, необходимо настроить WebDriverWait , чтобы элемент был кликабельным , и вы можете использоватьиз следующих решений:

yellowpages

1 голос
/ 01 июля 2019

Вместо того чтобы щелкнуть элемент span, вы можете попробовать щелкнуть тег привязки, как показано ниже.

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