繁体   English   中英

如何使用Selenium Web驱动程序python单击网页中目录列表的不同链接

[英]how to click on different links of directory listing in a web page using selenium web-driver python

我正在抓取一个网站Justdial,我需要单击每个配置文件的每个按钮( 立即查询 )。 我也尝试了下面的代码,但它显示了ElementClickInterceptedException。

browser.driver.find_element_by_class_name("green-btn").first.click()

我附上了图像以供参考,并附带了源代码。

在此处输入图片说明

以下是检查元素代码-

<li class="book-btn">
<!-- <span class="dtsbtntxt">Book a Table</span> -->
<!--  <span class="inner_spr in_po"></span> -->
                       <!-- <a title="Book Doctor Appointment" class="bookap green-btn result_loader_3 big_dn" href="javascript:void(0);" onClick="showloader('result', 'result_loader_3', this); _ct('DBookAppointment', 'lspg', '2'); openDiv('best_deal_div', 'bestdeal', '', '9999PX744.X744.130617175155.L7U9', 5);"><i id="result_loader_3"></i>Enquire Now</a> -->
                                                                                                                                                            <a class="green-btn result_loader_3  wdb" onclick="_ct('gtlp', 'lspg'); showloader('result', 'result_loader_3', this); trackEvent('Get The Lowest Price', 'onclicklowestprice', 'Get The Lowest Price');  return openDiv('best_deal_div', 'bestdeal', '', '9999PX744.X744.130617175155.L7U9', 5);" href="javascript:void(0);"><i id="result_loader_3"></i>Enquire Now</a>
                                                                            <span flg="2" docid="9999PX744_X744_130617175155_L7U9" countvalue="0">

请帮助,如何使用Selenium Web驱动程序单击每个按钮,我正在使用chrome Web驱动程序。

要单击Enquire Now按钮,请诱导WebDriverWaitelement_to_be_clickable ()以及使用以下定位器。

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[contains(@class,'green-btn')][contains(.,'Enquire Now')]"))).click()

您需要导入以下内容以执行上述代码。

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM