0

I am working on web scraping using selenium(python). There is chunk on code which is really long. So , i am using loops. When i am running the code lines separately, it is working fine but when i am using the loop, its not working. Here are the two errors:

WebDriverException: Message: unknown error: Element is not clickable at point (862, 13). Other element would receive the click: <div class="skycom_container">...</div>
(Session info: chrome=46.0.2490.80)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)

WebDriverException: Message: unknown error: Element is not clickable at point (924, 786). Other element would receive the click: <div id="silentUIblocker" style="display: block;"></div>
(Session info: chrome=46.0.2490.80)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)

Are these common or specific errors?? This is happening just before using the click() statement.

Here is my code:

from selenium import webdriver
import time
driver = webdriver.Chrome('C:\Users\name\Downloads\chromedriver_win32 (3)\chromedriver.exe')


driver.get('https://www.sky.com/shop/beta?s_tnt=87085:31:0')
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div/div[5]/article/button/div[1]/div[2]/div/h2').click()
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div/div[6]/section/div/div/div/div/div[1]/article/a').click()
driver.find_element_by_xpath('//*[@id="polaris"]/div/div/div/section/div/div[2]/a[2]').click()
driver.find_element_by_xpath('//*[@id="dsl-postcode"]').send_keys("E11 2LX")
driver.find_element_by_xpath('//*[@id="dsl-check-landline"]').click()
driver.find_element_by_xpath('//*[@id="dsl-addresses"]/option[2]').click()
driver.find_element_by_xpath('//*[@id="dsl-multiple-address-select"]').click()
driver.find_element_by_xpath('//*[@id="dsl-numberPortingNo"]').click()
driver.find_element_by_xpath('//*[@id="dsl-number-porting-submit"]').click()
driver.find_element_by_xpath('//*[@id="summaryBackLink"]').click()
driver.find_element_by_xpath('//*[@id="oneOffCostToolTip"]').click()
bb_pack = ["SKY_FIBRE_CAPPED", "BB_MAX"]
for i in bb_pack:
  driver.find_element_by_xpath('//*[@id="productButtonControls_%s"]/label' % i).click()
  bb_name1.append(driver.find_element_by_xpath('//*[@id="productButtonControls_%s"]/label' % i).text)
  pack = ["ANYTIME_EXTRA", "INTERNATIONAL_EXTRA"]
  for j in pack:
    driver.find_element_by_xpath('//*[@id="productButtonControls_ST_%s"]/label' % j).click()
    bb_name2.append(driver.find_element_by_xpath('//*[@id="productButtonControls_ST_%s"]/label' % j).text)
    #more details in this loop
Mohsin Awan
  • 1,176
  • 2
  • 12
  • 29
sky_bird
  • 247
  • 1
  • 4
  • 13
  • Consider upgrading your `Chrome` to 60.0 & `chromedriver` to 2.30. Thanks – undetected Selenium Aug 03 '17 at 08:59
  • Possible duplicate of [Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click:](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el) – undetected Selenium Aug 03 '17 at 09:01
  • This generally happens when Dom is getting updated and webdriver tries to click or another hidden element is blocking your element. Try giving wait/sleeps between the clicks. – Prakash Palnati Aug 03 '17 at 09:01
  • @Debanjan, upgrading is not an option for me at all. – sky_bird Aug 03 '17 at 09:03
  • @Prakash, i tried that, i have almost 400 such cases, applying sleep will take really long time. Is there any other option? – sky_bird Aug 03 '17 at 09:04
  • post your code. Solution is probably 1. `import time` 2. one line before the error comes put `time.sleep(10)`. – hansTheFranz Aug 03 '17 at 09:05
  • @DebanjanB check your exception, it is showing other element would receive the click:
    so, wait for this UI block div to disappear/elementNotVisible.
    – Prakash Palnati Aug 03 '17 at 09:10

2 Answers2

1

Use fluent wait as below. It will wait till your element is not ready on page:-

WebElement waitsss(WebDriver driver, By elementIdentifier){
     Wait<WebDriver> wait =
                new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
                                                 .pollingEvery(1, TimeUnit.SECONDS)
                                             .ignoring(NoSuchElementException.class);

return wait.until(new Function<WebDriver, WebElement>()
        {
            public WebElement apply(WebDriver driver) {
                   return driver.findElement(elementIdentifier);
            }
            });
}

The wait should work for you. If still the problem exists then use JavascriptExecutor . It will operate directly through JS. It should work. I am giving an example to click any element using JavascriptExecutor

WebElement element = driver.findElement(By.id("gbqfd"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

I just saw you are using python, in python, it should be something like below :-

driver.execute_script("arguments[0].click();", element)

The script should be like below :-

driver.execute_script("document.getElementsByClassName('skycom_container')[0].click()")
driver.execute_script("document.getElementById('silentUIblocker').click()")

Final code

    driver = webdriver.Chrome('C:\Users\name\Downloads\chromedriver_win32 (3)\chromedriver.exe')
    driver.implicitly_wait(30) # seconds
    driver.get('https://www.sky.com/shop/beta?s_tnt=87085:31:0')
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div/div[5]/article/button/div[1]/div[2]/div/h2').click()
    element=driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div/div[6]/section/div/div/div/div/div[1]/article/a') 
    driver.execute_script("arguments[0].click();", element)
    driver.find_element_by_xpath('//*[@id="polaris"]/div/div/div/section/div/div[2]/a[2]').click()
    driver.find_element_by_xpath('//*[@id="dsl-postcode"]').send_keys("E11 2LX")
    driver.find_element_by_xpath('//*[@id="dsl-check-landline"]').click()
    driver.find_element_by_xpath('//*[@id="dsl-addresses"]/option[2]').click()
    driver.find_element_by_xpath('//*[@id="dsl-multiple-address-select"]').click()
    driver.find_element_by_xpath('//*[@id="dsl-numberPortingNo"]').click()
    driver.find_element_by_xpath('//*[@id="dsl-number-porting-submit"]').click()
    driver.find_element_by_xpath('//*[@id="summaryBackLink"]').click()
    driver.find_element_by_xpath('//*[@id="oneOffCostToolTip"]').click()

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Could you please tell me the exact code lines for python? Thanx in advance..:) – sky_bird Aug 03 '17 at 10:14
  • As per the below link if you have classname or id you can click directly .. refer :- https://stackoverflow.com/questions/36987006/how-to-click-a-javascript-button-with-selenium – Shubham Jain Aug 03 '17 at 10:16
  • Is it possible for you to go through my code and help me? – sky_bird Aug 03 '17 at 10:32
  • can you tell me the id or class of the element which causing this error. be sure that id or class must be unique on the DOM – Shubham Jain Aug 03 '17 at 10:36
  • ... and
    . I got this from the error generated.
    – sky_bird Aug 03 '17 at 10:41
  • They are present in the dynamic content generated. – sky_bird Aug 03 '17 at 10:42
  • Added script in my answer. Now remove click operation from your script where you are clicking on it and replace with the code I have added in answer – Shubham Jain Aug 03 '17 at 10:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150942/discussion-between-sky-bird-and-shubham-jain). – sky_bird Aug 03 '17 at 11:15
  • you just remove accept answer for me ... any issues with code I have shared with you yesterday? .. you can't accept everyone's answer .. You have to select only one answer which works for you .. This is how stackoverflow works – Shubham Jain Aug 04 '17 at 07:44
  • No issues, it worked perfect for me. I got one part of answer from you and the other part from other reply. I didn't know i could accept only one. But, i am still waiting for the other part as the reply from you is still not able to help me. – sky_bird Aug 04 '17 at 10:38
  • You can create an another ticket for same. You can ask for a single issue at a ticket as per stackoverflow rules. while stack only allow you to help you in problem statement rather then writing the whole script. As your one issue is resolved. I suggest to you create an another ticket with the recent issue you are facing with the error in your question. hope it will help you – Shubham Jain Aug 04 '17 at 10:42
1

Try to add below imports

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

and insert below line just before making click():

WebDriverWait(driver, 10).until(EC.invisibility_of_element_located((By.ID, "silentUIblocker")))

This should allow you wait until element that intercept the click disappeared

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Yeah, it works. There is another error i just added. Could you see that too? – sky_bird Aug 03 '17 at 09:25
  • Try to solve in the same way: `WebDriverWait(driver, 10).until(EC.invisibility_of_element_located((By.CLASS_NAME, "skycom_container")))` – Andersson Aug 03 '17 at 09:57
  • Still not done..getting this error: C:\Anaconda2\lib\site-packages\selenium\webdriver\support\wait.pyc in until(self, method, message) 78 if time.time() > end_time: 79 break ---> 80 raise TimeoutException(message, screen, stacktrace) 81 82 def until_not(self, method, message=''): TimeoutException: Message: – sky_bird Aug 03 '17 at 10:05
  • Even the WebdriverWait has stopped working! Why is this even happening!!? I really need help..:( – sky_bird Aug 03 '17 at 10:12
  • Can you share page URL and description of what you're trying to do? – Andersson Aug 03 '17 at 10:23
  • I have already mentioned my code. I wanted the extract the details of different package combinations – sky_bird Aug 03 '17 at 10:24
  • Oh, sorry, I didn't notice your code. It seem that your issue is related to page scrolling: when you make first click page scrolled to required element to make new click. But those two clicks executed one after another disregarding whether page is already static or scrolling is in progress... So click intercepted by element that is currently visible on the same position on screen as target element. You can try to add appropriate verification to check this before making click.I think using `location_once_scrolled_into_view` property could help you – Andersson Aug 03 '17 at 10:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150949/discussion-between-sky-bird-and-andersson). – sky_bird Aug 03 '17 at 11:36