簡體   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