0

One of button does not appear on UI if zoom level of my browser is 100%, so once I zoom-in using the below code, that particular button appears on UI

driver.execute_script("document.body.style.zoom='80%'")

But action on that particular button does not happen even though button appears on UI in zoom-in state, instead I get this error message

{WebDriverException}Message: unknown error: Element is not clickable at point (891, 568). Other element would receive the click: (Session info: chrome=58.0.3029.110) (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86)

I do not get issue on my local machine, since that particular button appears on UI when zoom level of browser is 100%, it works well as I don't have to zoom-in.

But since I have to work on virtual box which I connect remotely using client machine, there I get this UI issue. Since virtual box screen appears inside my client machine's screen, its height gets reduced and that particular button disappears from UI at the bottom.

So need to zoom-in in order to perform this action and again reset zoom level to 100%. Am I doing anything wrong here or is there any other way to resolve such issue?

Edit: Attaching screenshot enter image description here

Shoaib Akhtar
  • 1,393
  • 5
  • 17
  • 46
  • can you try to scroll element instead of zoom out `JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("window.scrollBy(0,250)", "");` let me know if facing same issue – Trimantra Software Solution May 24 '17 at 07:31
  • 1
    change resolution of your client machine – san1deep2set3hi May 24 '17 at 07:53
  • @ShoaibAkhtar why are you using both `Java` & `Python` tags? What language is your client written in? Can you also consider posting the snippet of code that has the issues? It's pretty hard to debug you issue as it stands. Also a.f.a.i.k, Webdriver is not bound by the `display port` when doing actions like `.click()` so there might be another issue why this is not working. – iamdanchiv May 24 '17 at 08:13
  • @TrimantraSoftwareSolution I have attached screenshot now in question, even with scrollbar the button does not appear – Shoaib Akhtar May 24 '17 at 09:26
  • @san1deep2set3hi I have set maximum resolution, i.e 1400*796 for virtual box and 1400*900 for my client machine, reducing it will show too much big fonts. Also since virtual box screen appears inside client machine, so its height gets reduced and causing this issue – Shoaib Akhtar May 24 '17 at 09:29
  • @iamdanchiv Any solution in java or python is fine, I am using python though, so I used both tags. Since my code works well on my local machine where I don't have to zoom-in, so it seems code is fine. Only problem is when I gets such UI problem where I have to minimize the browser in order to do action on button(see attached image). – Shoaib Akhtar May 24 '17 at 09:36
  • @ShoaibAkhtar I think you are making your issue look more complex switching between different `Selenium` bindings of. `Java` & `Python`. Can you consider sticking to one binding at a time on one issue please? As per the IE known issues `100% Zoom` level is a mandatory requirement else you will run into diverse issues. If your buttons are not within the visible area use `JavaScriptExecutor` to move top/down/left/right. Can you share with us your work please? – undetected Selenium May 24 '17 at 09:49
  • @san1deep2set3hi Thanks for suggesting me to set proper resolution, it did the trick. I followed this(https://www.youtube.com/watch?v=VnHK-bhO8qY) video on how I can set custom resolution for my virtual box as I was not aware how to get those multiple options that can be set, setting proper resolution makes the button appears on UI when zoom level of browser is 100% on my virtual box which was not the case earlier. So my code works well now as I don't have zoom in after which I was getting issue. Add your comment with few point from here in separate answer please, will accept it. Thanks – Shoaib Akhtar May 25 '17 at 05:45
  • @ShoaibAkhtar Cool ;-) Good to hear. I have posted the comment as answer and would be happy if you accept it. Thanks – san1deep2set3hi May 25 '17 at 06:07

3 Answers3

1

You can simulate scroll using ActionChains class

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_...
ActionChains(driver).move_to_element(element).perform()
element.click()
Guy
  • 46,488
  • 10
  • 44
  • 88
0

I had the same issue. Driver should normally scroll to element on every Click, and it does, but it scrolls just so element just barely visible.

So it can sometimes be covered by another element, while driver thinks element is visible, and then theres an exception.

I found an nice workaround here: selenium scroll element into (center of) view

Center page so element is in middle of page:

In C#:

var js = d as IJavaScriptExecutor;

String scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
                                                    + "var elementTop = arguments[0].getBoundingClientRect().top;"
                                                    + "window.scrollBy(0, elementTop-(viewPortHeight/2));";

js.ExecuteScript(scrollElementIntoMiddle, element);

element.Click();

I tried zoom out at first, but at least with Chrome, Selenium cant work at all when zoomed out, so that didnt work.

George
  • 121
  • 2
0

For test automation if we have to deal with remote machines(e.g. in case of Sauce labs) it is always beneficial to take screen resolution seriously.

In today's world of responsive websites where we need to change browser window size quite often this requirement is becoming more effective.

In sauce labs we change resolution of client machine programatically using following

capabilities.setCapability("screenResolution", "1920x1080");

For different setup, we might need to follow steps as mentioned in comments by @ShoaibAkhtar above.

san1deep2set3hi
  • 4,904
  • 1
  • 23
  • 23