Now a days most of them using selenium as one of the scraping tool due
to its build in library and community support. Even though many of us
feel its hard to implement in selenium. In my previous post
explained how effectively we can use the selenium in different use
cases. Most of us known selenium is a automation testing tool. Currently
people using this as most successful scraping methodology. The most
scraping tools are developed with the help of selenium only. For
example Scrapy .
Issue:
One day I started to crawl Cricbuzz website. In the middle of crawling, The crawler should move to the next page. So I want not click the "next" button in the pagination list. But the crawler throws the issue like
WebDriverException: Message: Element is not clickable at point (918, 13). Other element would receive the click:
to resolve this, I tried to solve in using the below code ,
driver.find_element_by_class_name('pagination-next').click()
It does not solved fully. It works partially . So I tried another way to solve and code is
driver.implicitly_wait(10) el = driver.find_element_by_class_name('pagination-next') action = webdriver.common.action_chains.ActionChains(driver) action.move_to_element_with_offset(el, 918, 13) action.click() action.perform()
Even the action chains not performed well and kept throw the same issue.
After the long dig into the problem and found the stable solution.
Solution
The error says that , Another element is covering the element you are trying to click. So we could use execute_script() function to execute the click event.
The solution is
1 2 | element = driver.find_element_by_class_name('pagination-next') driver.execute_script("arguments[0].click();", element) |
The execute_script() method has 2 parameters. The first is the script, the second is a vararg in which you can place any parameters used in the script.
In this case we only need the element as parameter, but since it is a vararg our element is the first in the collection. For example you could also do driver.execute_script("arguments[0].click(); arguments[1].click();" element1, element2) This would click both elements passed
I hope this will help many of us.
No comments:
Post a Comment