Get display coordinates of tab using chromedriver and selenium - selenium

I am looking to find the co-ordinates to a specific tab in a chromedriver instance controlled by selenium.
The scenario is as follows: I have a chromedriver instance automated with selenium that contains multiple tabs. I am looking to pin specific tabs (not all of them) and in order to do that, I am using autoit to send the necessary mouse and keyboard commands to pin the actual tab. However, in order to do that, I need to know the screen/display coordinates of the tab (so I can send the mouse there).
The chromedriver has the coordinates to the actual browser, however I have been unable to find any reference to the coordinates of the tab.
Does anyone know how I could go about getting the coordinates of a specific tab?
Update: I am using c#

It would be a big help if you let me know what language you are coding the tests in, however this can be achieved through checking the position of your scrollbar as the AI does not have a monitor to be limited to a resolution, essentially it can see the whole of the web-page no matter what.
Below is a link to some of the usage for checking and comparing the scrolled status, even if this isn't a direct solution i'm positive it will point you in the right direction. (This is something i had to do not very long ago)
http://www.software-testing-tutorials-automation.com/2015/02/how-to-verify-scroll-present-on-browser.html
If you have any queries let me know,
All the best, Jack

Related

Can Selenium handle Browser Notifications in the OS?

In the screenshot below, I make a VoIP call from an incognito window to an account logged in in a normal Chrome window that is minimised. Therefore I receive the Chrome notification in the bottom right corner.
I am tasked with creating a front-end test to validate the text in the notification window, that would work for Windows, Linux, and MacOS situations.
Now this may or may not be a silly question, but is there a way that selenium can handle tasks related with this notification, for example validating the text that appears in it? I can't find anything online and I understand it is not a DOM element, so I wonder if it is even possible. Could someone provide a basic start point for finding this non DOM notification element if it is possible / how to go about testing it in the front end if selenium is not the answer? TIA.
Notification example

Sikuli integration with Selenium WebDriver

Can anyone tell me how to work with multiple edit boxes using Sikuli integrated Selenium WebDriver.
For example, I have 2 edit boxes which are labeled as username and password. So I want to click on the 1st edit box, then enter values and again want to click on the 2nd edit box. The size of the two edit boxes are the same. So how sikuli integrated Selenium WebDriver will identify which edit box to click.
If you are referring to the SikuliWebDriver, then this link has an example on the usage http://code.google.com/p/sikuli-api/wiki/SikuliWebDriver.
I would rather prefer using the Sikuli Java API and create wrapper functions around the Sikuli functions like click, type etc. This API is in active development and has good support available.
http://doc.sikuli.org/faq/030-java-dev.html
You can use the offset functionality. ie, you do not only use an image of the text field, but use a region of the screen which identifies something related to the text fields.
You may select a large rectangle which includes a heading above both fields, then use offset x/y coordinates and move the little crosshair over the exact location you wish to click/type.

Selenium clicks on a wrong link (or does not click on a link at all) on certain machines

I am using Selenium WebDriver 2.5.0 (tried 2.13.0, it did not help).
I am trying to click on a link like this:
driver.FindElement(By.PartialLinkText("Customer - Creation").Click();
Before it worked, but I have tried to run the scripts after 3 weeks and
I observe 3 different behaviors on 3 machines:
Machine A: There is no click on the link at all, also there is no error.
Machine B: It clicks a different link! Sometimes one above, sometimes one below.
Machine C (Virtual): It works.
I have not fully tested this (spent half a day today), but did anyone stumble upon such a behaviour?
I have restarted my PC, re-added the Selenium libraries.
"SendKeys(Enter)" helps, but this issue happened not only to links, but to at least radio boxes as well, where "SendKeys(Enter)" does not work.
Please share your thoughts.
Update: Browsers are the same on at least 2 machines, Internet Explorer 8.0
Answered by nebehr.g...#gmail.com at Selenium Issues:
This issue keeps popping up from time to time and is usually returned with request for clarifications. The bottom line is, InternetExplorerDriver calculates coordinates of some objects incorrectly and clicks in the wrong place. One reason for this is zoom value other than 100%; however it is reproducible for some controls for 100% zoom as well.
I suppose it would be helpful if you could create a sample page to demonstrate this issue. In the meantime why don't you use Javascript click() method for offending controls?
http://code.google.com/p/selenium/issues/detail?id=3052
One other thing to check for is the screen resolution (not the desktop resolution but the system level size of text and icons). I have two laptops in my office that are you used for testing, one running Windows 7 and the other running Windows 10. On both, the screen resolution was greater than 100% and Selenium was having problems moving the mouse to the correct location for mouse events like click and hover. As soon as the screen resolution was set to 100%, all mouse actions worked correctly.
Windows 7: http://windows.microsoft.com/en-us/windows7/make-the-text-on-your-screen-larger-or-smaller?v=t
Windows 10: https://superuser.com/questions/951199/windows-10-system-font-size-change
There is a lot of useful info in Andrey's answer and in the Selenium issue he mentions at https://code.google.com/p/selenium/issues/detail?id=3052. Just to tie all those pieces of info together and offer a successful workaround...
I too am experiencing the issue of clicks occurring at the wrong screen coordinates -- four years after the OP first mentioned it! As others have said:
The issue is related to InternetExplorerDriver. I have the problem
when testing IE 9, but not Chrome, Firefox or even IE 8.
As mentioned in the Selenium issue, the website I'm testing uses frames.
I tried several workarounds suggested in this post and elsewhere. All of the following did NOT help:
Updating to the latest InternetExplorerDriver (version 2.47.0)
Maximizing the browser window.
Setting browser zoom to 100%.
Using an action chain, with or without move_by_offset, instead of WebDriver's click() method.
As suggested by Andrey, what DID help is using JavaScript instead of WebDriver's click() method. Here's a line of Python code that does the trick:
driver.execute_script("jQuery('{}').click();".format(css_selector))
This assumes that "driver" is an instance of Selenium WebDriver, and "css_selector" is a string identifying the element you want to click, and that jQuery is loaded.
Sounds like the element isn't present in the page's HTML, but is instead added dynamically once the page is loaded. What happens depends on how fast the machine is and how unique the text is. I'll bet that if you added a long sleep (e.g., a minute) you'd get the same result on all 3 machines. If so, that indicates the single most classic Selenium testing problem - trying to act on pages that aren't complete. You need to find an element to wait on that will guarantee the presence of the link you'd like to click on.
I just had the same issue in FireFox. The zoom was at 100% and the selection was by xpath an certainly correct. Turned out the problem disappeared when I maximized the browerwindow!
code :(python api)
self.driver.maximize_window()

Automated testing of rendering in browsers

Can Selenium or any other automated tool check for the proper positioning of elements on a web page?
For example, when you look at OnStartups.com in IE 6, the main content that is supposed to be to the right of the menu is below it instead and you have to scroll down to read it. Can you query and get the coordinates of the div as they are actually displayed, and can you get the coordinates of the viewport to verify that the top left corner is actually within the viewable area?
I think comparing screenshots is the best thing you can do and I'm afraid there aren't robust tools for that, yet.
If I were you, I would create a script that navigates through every page of the site capturing a picture on each and then I would open a folder with all the results and it would probably take less than a minutes to check 20 or 30 of them. Sounds really dumb, but sometimes the easier alternative ends up being the best...
I'm afraid the best you could do is select a standard browser and than compare screenshots of other browser with the reference one.
I can't remember the specific one but some tool like Araxis merge was able to compare screenshots in a pretty intelligent way.
Selenium has assertions to check an element's position and size:
assertElementHeight(locator,pattern)
assertElementWidth(locator,pattern)
assertElementPositionLeft(locator,pattern)
assertElementPositionTop(locator,pattern)
A simple test to check the rendering in the OPs example could be to write
assertElementPositionTop(//*[#id='main_content'],0)
thus checking whether #main_content is rendered at the top or somewhere else.

Squeak System Browser Questions

I am using (a school modified version of) the "Squeak By Example" (SBE) image for a OOP/OOD class. However, my System Browser is missing a few features that appear in SBE. I assume there are some configuration options that can get them back for me, but I can't find them yet.
My questions are:
1) How do I get the buttons back? In the bottom pane there should be a bunch of button (browse, senders, implementors, versions, ..., source). My buttons are missing.
2) How do I get the small workspace area above the buttons to appear? There is supposed to be an area that I can type in, below the top panes, and above the buttons, but it doesn't appear.
Thanks in advance!
Robert
Edit - I did fool around in the Preferences Browser and tried a lot of settings. I managed to make the buttons come back and then later got that small (unknown name) workspace pane back, but I have no idea how. I have tried to systematically turn stuff off again to find out what setting(s) controlled what, but I was unable to determine what controlled either problem. So even though I have it working, I would like some squeak/smalltalk knowledgeable person to let me know how to control these as it might help me learn...
"In the bottom pane there should be a bunch of button (browse, senders, implementors, versions, ..., source). " -- switch on the optionalButtons preference in the preferences browser.
The "area that I can type in, below the top panes, and above the buttons, but it doesn't appear" sounds like the annotation pane - this gives you summary information about the method you're currently viewing, and it's controlled by the annotationPanes preference. Alternatively you may be referring to the Mercury Panel which is used for fast navigation to other classes and methods; this is (of course :-) controlled by the mercuryPanel preference.
If you've been messing around, you may also find that you now have an incorrect system browser selected. Squeak has a choice of browsers which can act as the System Browser. You can choose between them by clicking the menu button on the System Browser and selecting "Choose new default Browser". Open a new browser window to see what effect this has had.
You may also want to try a Pharo image which has everything configured the way you want by default.
Do you have access to the Preferences Browser? It should be in the main system menu. You can alter all sorts of things via this browser, including which buttons appear in teh system browser?