1

I navigate to the website, switch to the correct iframe, and everything seems to work fine, but once I need to interact with an element it throws the error:

selenium.common.exceptions.ElementNotVisibleException

CODE:

# IMPORT
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep

# NAVIGATE
driver = webdriver.Chrome("C:\\Program Files (X86)\\Google\\chromedriver.exe")
driver.get('http://www.foxnews.com/politics/2018/01/17/ice-plans-major-sweep-in-san-francisco-area-report-says.html')

# SWITCH TO IFRAME
iframe = driver.find_element_by_xpath('//IFRAME[contains(@src, "https://spoxy-shard4.spot.im/v2/spot/")]')
driver.switch_to.frame(iframe)

driver.find_element_by_xpath("//INPUT[@placeholder='Your nickname...']").click()

I've tried targeting other elements as well, but it always gives an error:

"no such element"
"element not found"
"is not clickable at point (485, 873). Other element would receive the click: <p class="alert-text">...</p>".

1 Answers1

1

I visited a website and I found two problems, I am not 100% sure what you are trying to do so I am considering you are trying to click on comment input field.

First Problem Sometimes this yellow banner appears at the bottom, which is on top of all the elements so if you will try to click on any element which is beneath this you will you will get the ElementNotVisible exception with message that someother element might receive the click.

Solution: Wait until banner appears and if it does close the banner

Second Problem You are trying to click on the input field which is hidden so even if banner doesn't appear you will get the ElementNotVisible Exception.

Solution: Rather than clicking on the input element click on it's parent div

Here is the code which is working.

 def is_element_exist(identifier, timeout=30):
    wait = WebDriverWait(driver, timeout)
    try:
        return wait.until(EC.presence_of_element_located(identifier))
    except TimeoutException:
        return None


def accept_alert(timeout=30):
    alert = WebDriverWait(driver, timeout).until(EC.alert_is_present())
    print alert.text
    driver.switch_to.alert.accept()


# NAVIGATE
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome("h:\\bin\\chromedriver.exe", )
driver.get('http://www.foxnews.com/politics/2018/01/17/ice-plans-major-sweep-in-san-francisco-area-report-says.html')

#Wait for yellow popup footer and close it
close_button = is_element_exist((By.XPATH, "//a[@class='close']"), 10)
if close_button:
    close_button.click()

# SWITCH TO IFRAME
iframe = driver.find_element_by_xpath('//IFRAME[contains(@src, "https://spoxy-shard4.spot.im/v2/spot/")]')
driver.switch_to.frame(iframe)

driver.find_element_by_xpath("//*[@class='sppre_editor']/div").click()

#Wait and accept the alert
accept_alert()
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
  • It doesn't seem to click on the correct element. I'm trying to click on the area to leave a comment. It should respond by creating a popup asking to login. – Chris Hayes Jan 17 '18 at 16:06
  • I get a "NoSuchElementException". I think it maybe due to some kind of javascript protection. Similar to this maybe? https://stackoverflow.com/questions/27927964/selenium-element-not-visible-exception – Chris Hayes Jan 17 '18 at 19:37
  • could be if your internet connection is slow. or if site is working slow. however above code works perfectly find on side. I am able to land to singup page for comment. – Gaurang Shah Jan 18 '18 at 18:00