0

1 click button in website it shown iframe like popup and I can edit it but I cant close iframe I try to use X button but when mouse focus in button it change the class name and shown text on mouse , it don't have id.

this is source of button

<a class="jbox-close" title="Close" onmouseover="$(this).addClass('jbox-close-hover');" onmouseout="$(this).removeClass('jbox-close-hover');" style="position:absolute; display:block; cursor:pointer; top:11px; right:11px; width:15px; height:15px;"></a>

this is code focus mouse
<a class="jbox-close jbox-close-hover" title="Close" onmouseover="$(this).addClass('jbox-close-hover');" onmouseout="$(this).removeClass('jbox-close-hover');" style="position:absolute; display:block; cursor:pointer; top:11px; right:11px; width:15px; height:15px;"></a>

this is my code

        for link in tittle:
            a = link.get_attribute('title')
            if (a == "Packaging Details"):
                link.click()
                time.sleep(2)
                print(driver.current_url)
                iframe=driver.find_element_by_tag_name('iframe')
                driver.switch_to.frame(iframe)
                time.sleep(2)
                print(driver.find_element_by_id("width").get_attribute('value'))
                print(type(driver.find_element_by_id("width").get_attribute('value')))
                print(widthctn)
                driver.find_element_by_id("width").send_keys("",widthctn)
                time.sleep(1)
                driver.find_element_by_name("btnSave").click()
                time.sleep(1)
                driver.switch_to.window(driver.window_handles[1])
``
and this error

raceback (most recent call last): File "C:/Users/dtung/PycharmProjects/BS4/multiple tab.py", line 79, in link.click() File "C:\Users\dtung\miniconda3\envs\BS4\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Users\dtung\miniconda3\envs\BS4\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "C:\Users\dtung\miniconda3\envs\BS4\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\dtung\miniconda3\envs\BS4\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (257, 505). Other element would receive the click: (Session info: chrome=81.0.4044.113)


2 Answers2

0

You can't close iframe instead of that once you finished processsing elements on a iframe you can switch control back to your parent window using driver.switch_to.default_content()

find more on how to handle iframes

SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
0

If you are asking about iframes, you can find your answer here Selenium and iframe in html,

But your error looks like some element/alert is hiding your actual element where you want to click. You can achieve click using js executor if element is not visible or hidden by some other element. eg: assuming click is failed,

btnSave = driver.find_element_by_name("btnSave")
driver.execute_script('arguments[0].click();', btnSave)
Pradeep
  • 38
  • 3
  • Thanks for your answer it opens 2 frames,Your answers help me solve the problem but I want to learn more about how to close it to be able to optimize. NOTE: hiding element is link.click() it open iframe – Tùng Dương Apr 21 '20 at 06:03
  • your code looks like you are referring to windows, in that case you can close it using driver.close() and if you want to switch out of iframe, use this driver.switch_to.default_content() – Pradeep Apr 21 '20 at 12:38
  • driver.close() it close page. driver.switch_to.default_content() it still can't close iframe just switch out iframe and Many iframes overlap. – Tùng Dương Apr 22 '20 at 04:18
  • It would be good if you can provide page source or url, how you are trying to close iframe. In general there is no way we can close iframe. But we can remove it from page using js. – Pradeep Apr 22 '20 at 06:30
  • sorry but I can't. Where can I find out about it, js. i just beginner and hope learning more. P/S:when I code driver.find_element_by_id("width").get_attribute('value') if attribute doesn't exist Is my code faulty?.Thanks U again – Tùng Dương Apr 23 '20 at 04:37