2017-08-09 157 views
0

我想運行一個python腳本,它將繼續點擊加載更多按鈕,直到它消失。而我試圖代碼如下所示:這裏元素不可點擊硒python

import csv 
import time 
import re 
from bs4 import BeautifulSoup 
from selenium.common.exceptions import NoSuchElementException 
from selenium import webdriver 
import requests 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 

page=requests.get('https://www.killerfeatures.com/mobile/brands').content 
soup1=BeautifulSoup(page,"html5lib") 
brndsbox=soup1.find_all("div",attrs={"class":"brndsbox"}) 
count=0 
brand_link=[] 
for each in brndsbox: 
    x= each.find("span") 
    j=str(x).split('=')[5].split('"><')[0].replace('"',"") 
    brand_link+=["https://www.killerfeatures.com"+j] 


chromedriver=r"D:\MOBILE_JUNE_22_2017\old_files_\price raja mobile\working\chromedriver.exe" 
driver=webdriver.Chrome(chromedriver) 
for url in brand_link: 
    print url 
    driver.get(url) 
    track_count=0 
    while True: 
     try: 

      element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "loadMoreRecords")) ) 
      element.click() 
      print "click", track_count 
      time.sleep(5) 
      track_count+=1 
     except NoSuchElementException: 
      break 

print "complete" 

問題是,它是示值誤差爲selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (636, 583)它爲什麼發生任何想法。我已經使用了一個明確的等待,直到元素可見。在那之後,我也遇到了錯誤。提前致謝!

+0

任何問題的代碼? –

+0

代碼運行良好,但進入無限循環。它不斷點擊,雖然元素不存在。不知道爲什麼會發生 –

回答

1

使用JavascriptExecutor。它將通過JS直接操作。它應該工作。我給一個例子,點擊使用JavascriptExecutor

任何元素

代碼應該是象下面這樣: -

element=driver.find_element_by_xpath('YOURXPATH') 
driver.execute_script("arguments[0].click();", element) 

注: - 改變定位在上面的代碼按需要

希望它會幫助你:)