0

I am trying to run a python script which will keep on clicking the load more button till it disappear. the code which I am trying is as shown below:

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"

Problem here is it is showing error as selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (636, 583) any idea why it is happening. I have already used a explicit wait till element is visible. after that also I am getting error. Thanks in advance!

2
  • any issue with code? Commented Aug 9, 2017 at 11:10
  • the code run fine but it goes into infinite loop. It keep on clicking though the element is not present. Not sure why it is happening Commented Aug 9, 2017 at 11:12

1 Answer 1

1

Use JavascriptExecutor . It will operate directly through JS. It should work. I am giving an example to click any element using JavascriptExecutor

Code should be like below :-

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

Note :- change the locator in above code as per need

Hope it will help you :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.