Milano Slesarik Milano Slesarik - 14 days ago 6
Python Question

Python - Selenium: Element is not currently visible and may not be manipulated

I'm trying to find out, why the following error is being raised:

Element is not currently visible and may not be manipulated


I want to find the
next
button and click it.

This is the page: example page

I have this code in my
driver
class:

def click_next(self):
try:
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
self.driver.find_element_by_xpath('//li[@class="paging-item"]/a').click()
except:
raise
return False


Do you know where is the problem?

Answer

Why are you using xpath to search for a class name when there is a method exactly for that, find_element_by_class_name?

PhantomJS often behaves in a weird way. Many times when an Element is not currently visible and may not be manipulated it's because of the window size. Try re-sizing the window, that worked for me (tested on Ubuntu 14.04 with Phantom JS 1.9.8).

from selenium import webdriver

url = 'http://www.sreality.cz/hledani/prodej/byty/praha-2,praha-3?stavba=cihlova&vlastnictvi=osobni&strana=1'

browser = webdriver.PhantomJS()
browser.set_window_size(1920, 1080)  # choose a resolution big enough
browser.get(url)

next_arrow = browser.find_element_by_class_name('paging-next')
next_arrow.click()
Comments