Element is not currently visible and may not be manipulated exception #11637

Open
skov555 opened this Issue Sep 23, 2013 · 66 comments

Projects

None yet
@skov555
skov555 commented Sep 23, 2013

Simple code in selenium works in both Firefox driver and HtmlUnit driver but it
fails with PhantomJs as it returns element not visible exception.

Steps.

  1. Go to page https://signup.live.com/
  2. Select element by id iBirthDay
  3. Set value by value
@fraogongi

I get the same problem. I have a form with just two input fields. Works perfectly OK in Firefox and other browsers, but when using PhantomJS, I get an

"InvalidElementStateException: Message: u'Error Message => 'Element is not currently interactable and may not be manipulated"

I can clearly see the the input elements are present when I take a screenshot via selenium functions.

Is this an issue with PhantomJS itself?

@simon-k
simon-k commented Oct 21, 2013

Have the same problem. Using Coypu. When running in Firefox everything works fine, but in PhantomJS I get a ElementNotVisibleException when I try to sumulate a link click.

From screenshots I can see that the link is visible.

@Fak3
Fak3 commented Oct 23, 2013

Same problem with pahntomjs version 1.9.2.
To reproduce - navigate to the same page twice, then try to click visible element
webdriver.get(url)
webdriver.get(url)
webdriver.find('#my_elem').click()

raises ElementNotVisibleException: 'Element is not currently visible and may not be manipulated'

@TheNorthEestern

I'm also encountering this issue (works fine in Firefox, chokes in PhantomJS) using WebDriver with Python

Here's the snippet in question:

driver.execute_script("window.scrollTo("+ str(selected_sites_textbox_location['x']) + ","+ str(selected_sites_textbox_location['y']) +");")

for site_name in site_names:
     for num_placements in range(scraper.conf['sites'][site_name]):
           # Code chokes here.
           selected_sites_textbox.send_keys(site_name)
           sleep(2)
           selected_sites_textbox.send_keys(Keys.RETURN)
@shankisg
shankisg commented Nov 8, 2013

Same for me, works on Firefox but not working with PhantomJS.
"phantomjs ElementNotVisibleException: Message: u'Error Message => 'Element is not currently visible and may not be manipulated"

@shankisg
shankisg commented Nov 8, 2013

Hi guys, I just found a solution. Try this
browser = webdriver.PhantomJS()
browser.set_window_size(1124, 850) # set browser size.
browser.get("http:example.com") # Load page

The solution is we need to set a fake browser size before doing browser.get("").

Hope this helps

@skov555
skov555 commented Nov 8, 2013

I was setting window, so it will not solve my issue. I am taking screenshot and I can see element there but it still will give this error when I try to change value of that element.

@Synesso
Synesso commented Nov 11, 2013

I set the window to maximize and the problem persisted. Looking at the screenshot though it was only 400px wide. The element was visible, but on a hunch I set the screen dimensions to exactly 1024px wide and the test passed.

@simplexx
simplexx commented Dec 8, 2013

I also have this problem and i have an idea why it's happening. It seems like when there is a div, (which is always visible and does not scroll) (Like on the live.com website), The displayed property for this div is true, but for all other elements on that page, it is false.

@nchagrass

I also have this problem, resizing the window does fix it.

Thanks to @shankig

@skov555
skov555 commented Dec 11, 2013

Resizing or changing window size is not fixing it. In your case it is not a issue but you just did not set window size correctly. Issue is when you have window set up and on screen shot you can see element but browser reports it as invisible.

@TheNorthEestern

Resizing the window seems to have remedied the issue for me, but this isn't really a fix, considering the original script ran fine without a hitch in Firefox without having to resize the window.

@simplexx

Like i said, this problem occurs on certain websites when there is a div, which is fixed and always visible. check https://signup.live.com/

@shankisg

Hi guys, I have tried a lot with different ways to solve the issue. But resizing the window was the last option available to me.

@mokies
mokies commented Jan 7, 2014

I am experiencing this issue with clearly visible radio buttons. Tests run fine in Firefox but fail in phantonjs, the page resize work around does not resolve the issue for me.

@micurley

Was just running into this issue myself
process was clearing text input value then entering new value
changed driver.clear() to driver.clear w/o parens and works fine

@jdewit
jdewit commented Feb 7, 2014

using protractor.js, setting window size fixed this error. thanks @shankig

driver.manage().window().setSize(1000, 800);

@macdonjo

Calling: element.clear before using element.set_keys works for me! Thanks micurley.

@Saren-Arterius

Thanks @shankig
browser.set_window_size(1440, 900) # Fixes "Element is not currently interactable and may not be manipulated" in PhantomJS 1.9.7

@nishannakarmi

Thanks @shankig
browser.set_window_size(1120, 550) works

@mjhea0
mjhea0 commented Aug 25, 2014

Thanks @shankig

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.set_window_size(1120, 550)
driver.get("https://duckduckgo.com/")
driver.find_element_by_id('search_form_input_homepage').send_keys("realpython")
driver.find_element_by_id("search_button_homepage").click()
print driver.current_url
driver.quit()
@lacymorrow

A different fix that worked for me was to set the elementScrollBehavior (desired) capability. Changing from the default (0) to 1 will cause Selenium to scroll target elements to the bottom of the page instead of the top.
These correspond to the behaviors of the JavaScript scrollIntoView() function.

It will work any fixed elements at the top of the page.

Found at https://code.google.com/p/selenium/issues/detail?id=5764

@lhridley

Encountered the same issue with PhantomJS (1.9.7) , CasperJS (1.1.beta3) and PhantomCSS. Using a casper.click() or a casper.mouse.click() on a tag element that is clearly visible and clickable via a media query in a CSS3 stylesheet in a browser at screen sizes below 940px (css style --> display: block) but is hidden on larger screens (css style: display: none) generates the same error:

error: "CasperError: No element matching selector found: a#megamenu-button-mobile"

stack: in getElementBounds() in /usr/local/casperjs/modules/casper.js:1039

in computeCenter() in /usr/local/casperjs/modules/mouse.js:56
in processEvent() in /usr/local/casperjs/modules/mouse.js:78
in click() in /usr/local/casperjs/modules/mouse.js:97
in anonymous() in test/homepage.js:115
in anonymous() in test/homepage.js:147
in _forEach() in /usr/local/casperjs/modules/casper.js:621

Error does not occur with SlimerJS (0.9), CasperJS (1.1.beta3) and PhantomCSS.

Elements are visible and clickable in Firefox, Safari and Chrome.

@tit
tit commented May 5, 2015
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :phantomjs
driver.manage.window.resize_to 1920, 1080

Work! Thanx!

@RamyaBNayak

Setting the window size or maximize fixed the issue.
driver.Manage().Window.Maximize();

Thanks @shankig

@mirraj2
mirraj2 commented Jun 14, 2015

Setting the window size didn't work for me, but calling driver.manage().window().maximize() DID work.

@furqi01
furqi01 commented Jun 14, 2015

Hey Guys!
This issue is due to the following reasons:
i) Duplicated element locators for e.g (identical cssSelectors, Xpath etc.)
ii) You are trying to access an element that is hidden and not visible.

For resolution of first reason, you need to write unique cssSelector/xpath etc. that only locate the required element.

For resolution of 2nd, you can use explicit wait and wait till the element is not visible. Once it is visible then you can perform your operations.
Syntax: new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath/cssSelector("your path here")));

The third solution that would really works for you in any case is to take the size of the identical elements, and then locating the exact element for you using this:

int ok_size=driver.findElements(By.xpath/cssSelector("your path herel")).size();
driver.findElements(By.xpath/cssSelector("your path here']")).get(ok_size-1).click();

You can set "ok_size-1" or "ok_size-2" depending upon your requirement i-e which place element you want to locate either on first place or second place or so.

I will recommend this third solution to all as it really works for me in all the cases.
Cheers!

@A1rPun
A1rPun commented Jun 30, 2015

Thank you for the real answer @furqi01 . Resolved my issue.

@furqi01
furqi01 commented Jun 30, 2015

my pleasure @A1rPun :)

@tdphillips tdphillips referenced this issue in DirectEmployers/MyJobs Jul 1, 2015
Merged

Selenium! <PD-1471><PD-1520><PD-1521><PD-1522> #1617

@raneyvik

Hello All,

I have tried to automate airtel website (https://business.airtel.in/escares/) using phantomjs executable and its working,

But when I am trying to run it on Linux Server.I have installed Phantom Js 1.9.8 on redhat linux box and trying to run the class.Its showing
"Element is currently not intractable and may not be manipulated"

I have tried setting the window size as well..Setted several sizes but no luck.

Could any1 please tell me how to resolve this issue.I am stuck from quite a long time.

@ozbrancov

I'm using PhantomJS 1.9 on Ubuntu 14.04 and I have the same issue. I've tried everything got get PhantomJS to click an element that's in a dropdown list. The browser does not perform ActionChains for me like Firefox and Chrome, so I then tried using pure clicks. Once again Firefox and Chrome work great but PhantomJS still gives me:

"Element is not currently interactable and may not be manipulated"

I've taken furqi01 's advice and followed it closely and it still doesn't work.

@furqi01
furqi01 commented Oct 8, 2015

@ozbrancov: can you provide the script here?

@brightWeen

Setting the window size or maximize fixed the issue.
driver.manage().wndow.maximize();

Thanks @shankisg

@Artgit
Artgit commented Jan 2, 2016

I have the same issue, can't process following site https://www.mycommerce.com/affiliate-login on CentOS 5.8 and PhantomJS 1.9.8

After this java command:
WebElement usernameInput = mainDriver.findElement(By.name("PUBLISHER_ID"));

I have a following error:

Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: {"errorMessage":"Element is not currently interactable and may not be manipulated","request":{"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"49","Content-Type":"application/json; charset=utf-8","Host":"localhost:7727"},"httpVersion":"1.1","method":"POST","post":"{"id":":,"url":"/value","urlParsed":{"anchor":"","query":"","file":"value","directory":"/","path":"/value","relative":"/value","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/value","queryKey":{},"chunks":["value"]},"urlOriginal"......}}

PhantomJS 1.9.8 can't process this site :(

How to fix it ?

P.S.

setSize()/maximize() also doesn't work

@furqi01
furqi01 commented Jan 3, 2016

@Artgit You can try by introducing an implicit wait and before the command and then locate the element by xpath using this command:
mainDriver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
WebElement usernameInput = mainDriver.findElement(By.xpath(".//*[@id='ClientLoginShareIt']/div[1]/div[1]/input"));

After reviewing the above issue it seems like it's having difficulty to locate the element. So in my opinion if you introduced an implicit wait and then locate the element using xpath (commands written above) then it would help to resolve this issue.
Let me know if you find this helpful.

@Artgit
Artgit commented Jan 3, 2016

@furqi01 Thanks for your answer !

Unfortunately the same issue. It can locate element but fails on the following line(Sorry, I was wrong in my previous post.. this is the same line as previously.. it fails on the sendKeys method ):

usernameInput.sendKeys(USERNAME);

Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: {"errorMessage":"Element is not currently interactable and may not be manipulated"

@Artgit
Artgit commented Jan 3, 2016

I don't know why but PhantomJS 1.9.8 on CentOS 5.8 can't properly render this site.. this is a screenshot:

@furqi01
furqi01 commented Jan 4, 2016

@Artgit so you need to resolve this issue of rendering the page completely and to me this is home page snapshot where there is no Paricipant ID field like on login page.
Another thing, are you using some ad blockers type extensions? Seems like you are using some ad blockers which are enabled and causing the page not to render completely.
Disable such extensions and then run the test. Hopefully, it would work!

Let me know if this helps you.

@Artgit
Artgit commented Jan 4, 2016

@furqi01 this a screenshot of a login page .. the same story..
Also, I don't use any adblocks.

padeditor-shareit-publisher_error

@furqi01
furqi01 commented Jan 4, 2016

hmm..quite strange...I can reproduce the same by enabling browser ad-ons/extensions actually.

@Artgit
Artgit commented Jan 4, 2016

I don't know how to check these add-ons on CentOS 5.8.. will dig into it

@Artgit
Artgit commented Jan 4, 2016

I think this issue related to SSL.. :

Connecting to cdn.mycommerce.com|54.240.184.105|:443... connected.
OpenSSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

How to disable SSL validation on PhantomJS side ?

@furqi01
furqi01 commented Jan 4, 2016

@Artgit
alright..then do try this. Below command will help you resolve the SSL related issue:
phantomjs --ignore-ssl-errors=yes [phantomOptions] script.js [scriptOptions]

Here is a complete list of command line options for phantomjs is available here: http://phantomjs.org/api/command-line.html.
I hope this helps.

@Artgit
Artgit commented Jan 4, 2016

I have tried different combination of :

capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--ssl-protocol=any", "--web-security=false", "--ignore-ssl-errors=true"});

Right now, I think this issue related to tlsv1.2

Does PhantomJS support tlsv1.2 ?

@furqi01
furqi01 commented Jan 4, 2016

Nopz.
You can go through this thread: #13496

@Artgit
Artgit commented Jan 4, 2016

Well.. is it possible to inject external css files to the loaded page via PhantomJS ? I can manually download css files from this site and inject it into the page on the fly.. Will it work ?

@nautilusPrime

In case, someone encounters this issue in nodejs running selenium-webdriver and phantomjs 2.1.1, the following work around worked for me.
Due to webdriver's asynchronous nature, one needs to handle the browser 'resize' within the returned promise's success callback. i.e :

driver.get(URL).then(function () {
        driver.manage().window().maximize();
    });
@jhedstrom jhedstrom referenced this issue in phase2/grunt-drupal-tasks Mar 9, 2016
Open

Use PhantomJS instead of Zombie #249

@irinag896

I have the same issue ...i am using webdriver + groovy....NOTHING helped me.........:(

@pathfinder2104
pathfinder2104 commented May 5, 2016 edited

For me I was facing the same issue in one of my project, what I was able to get the element and able to enter the text in Selenium code, but not with phantom JS and serenity framework, I did focus on the element using this: ((JavascriptExecutor)driver).executeScript("document.getElementById('ELEMENT_ID').focus());
This worked for me.

@zilahir
zilahir commented May 5, 2016

i am having the same issue, non of these suggestions helped me, already tried different browser sizes, and also maximizing. the strange thing is when i creating a screesnhot, everything is visible, but i cant click on the element, and even stranger that when i am getting the source code before the element click part, i am getting the code from the previous "window". (i am loading a new iframe when click on the next button on the prev page).

may you have any suggestions?

@furqi01
furqi01 commented May 5, 2016

@zilahir can you check that the element on which you want to click is in an iframe or the element locator is not unique for that element? or what error you are getting in the console?

@zilahir
zilahir commented May 5, 2016

@furqi01 before the clicking the desired element, i am unselecting the prev frame, and then selecting the current one. this step passes. but then, the click returns:
ValueError: Element locator '//*[@id="print_ok"]' did not match any elements.

@furqi01
furqi01 commented May 5, 2016 edited

@zilahir thank you!
Have you introduced any conditional wait?
or if you can try another thing, that enter this xpath in firepath using firefox and check if it's locating the element their, just to confirm that xpath doesn't have any issues.

@miguelmota

This worked for me

 browser.setViewportSize({
    width: 1920,
    height: 1080
});
@Nunna09
Nunna09 commented May 26, 2016

i am having the same issue, non of these suggestions helped me, already tried different browser sizes, and also maximizing. the strange thing is when i creating a screesnhot, everything is visible, but i cant click on the element, and even stranger that when i am getting the source code before the element click part, i am getting the code from the previous "window". (i am loading a new iframe when click on the next button on the prev page).

may you have any suggestions?

I have the same issue as ZILAHIR. Tried all the things posted in here. Can somebody suggest the fix please..?

@furqi01
furqi01 commented May 26, 2016

@Nunna09 can you provide the URL and steps to perform that actions?
May be then I can help..

@Nunna09
Nunna09 commented May 26, 2016

@furqi01, actually the issue is with the object as it is unable to identify. And the cause is every time I run the test it picks up the website from the cache so it does not need to open the sub window and actually performing the action. But in my test I have given xpath to find the sub window.

Thanks furgi01.

@Nunna09
Nunna09 commented May 26, 2016 edited

its resolved now

@furqi01
furqi01 commented May 26, 2016

cool!

@Nunna09
Nunna09 commented May 26, 2016

Hi

can anyone give the links for headless browser testing and phantomjs documentation ..?
I am doing POC for my new project and I need to highlight few points.
Any help must be appreciated.

Thanks,
Nunna

@mikeatlas

Encountered this with Agouti (Go / Golang) and PhantomJS. Solution to resize the window worked for me:

    window, err := page.Session().GetWindow()
    Expect(err).To(BeNil())
    window.SetSize(1920, 1080)

This resolved "Element is not currently visible" issues when trying to interact with an element (e.g., click it).

@gabernardone

This worked for me
driver.Manage().Window.Maximize();

@tyleralves

thanks @shankisg

@vaskort
vaskort commented Oct 21, 2016 edited

What helped me in my case to have consistent results in PhantomJS is to scroll to the element you want to interact before setting its value for instance:

var emailInput = browser.element('#emailInput');
browser.scroll('#emailInput');
emailInput.setValue('test@test.com');

I use WebdriverIO

@kag0
kag0 commented Dec 3, 2016

same issue, selenium java 3.0.1, phantom 2.1.1, resizing window does not help.

@mrtamb9
mrtamb9 commented Dec 5, 2016 edited

Thanks @shankig, resize window helps me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment