Selenium Dom values are not updated - selenium

I am seeing a problem in Selenium with IE6/8 that is giving me some bad time. The problem is that the DOM window properties are not updated after actions are done and always return the default values.
To give you couple of examples:
Browser is first launched in normal size (document.body.clientHeight = 500px). After I do window maximizing, the property stays 500px!
Scroll top offset (document.body.scrollop) is initially 0, I then do scrolling, when I access the property it is till 0!
Has anyone seen this problem before or might know what is causing it?

To access the Window and document object in Selenium test you need to put this.browserbot.getUserWindow(). It gives you access to the page that Selenium is working on.
int offset = Convert.ToInt32(selenium.GetEval("this.browserbot.getUserWindow().document.body.scrollTop"));

Related

Testcafe waits for element to appear when using .visible even though the element already visible on the loaded page

I have an if statement which checks that if element is visible, then do something else.
if (await locators.courseHeaderEditButton.visible) {
//code
}
However, I'm noticing that in this case even though the element is visible on the page, TestCafe seems to wait for element to appear as defined in my testcaferc.json file.
"selectorTimeout": 15000,
"assertionTimeout": 15000,
Video where the page has loaded and the element is visible but TestCafe still waits before proceeding on:
https://recordit.co/Bbo9qZFWAL
If I switch to exists as seen below
if (await locators.courseHeaderEditButton.exists){
//code
}
Then TestCafe does not wait for 15 seconds and proceeds immediately.
Using visible does not always follow the same behavior though, sometimes TestCafe proceeds immediately without waiting for 15 seconds when the element is visible.
Any idea why visible acts this way in this example?
Thanks in advance for any response.
The exists property and the visibility property work differently.
The exists only checks if the element is presented on the page. Meanwhile, the visibility property checks that the element is visible (does not have visibility:hidden or display: none), has clientWidth/clientHeight greater than 0, and is not overlapped by any other element.
Perhaps one of these conditions is not met in your case.
Please share your full example to reproduce the issue. It will allow me to research it further.

Selenium evaluates DOM or Visible elements

I would like to understand how Selenium evaluates the page.
I have set of test to check elements on the page. Written with Nunit, Selenium and PhantomJS as Driver.
Page.Visit();
Page.FindElement(By.Id("testid").Text.Should().NotBeNull(); // PASS
Page.FindElement(By.Id("testid").Text.Should().NotBeEmpty(); // does NOT PASS
The test DOES NOT pass if the browser size is set to be very small:
driver.Manage().Window.Size = new Size(10,10);
Based on this test, it is confusing how PhantomJS evaluates the page. I always thought that it checks the DOM but seems like for element TEXT it evaluates based on visibility!
Although this surprised me too when I first discovered it, Selenium will only find elements visible in the viewport of the browser. For this reason, you will want to ensure at the start of your tests that your browser viewport is large enough to accommodate the content of your application.
Typically this can be done by maximizing the browser window. If you are using Windows, triggering the F11 key via Selenium should work.

How to wait until page freezes in Selenium WebDriver?

We have got following logic on frontend - so when new page is loaded, screen is auto scrolling to specific section and I have a script which clicks on the specific element at that time. Hence, while this movement is occurring following error is appearing due to the fact that selenium is clicking on wrong element:
"Element is not clickable at point (x, y). Other element would receive
the click..."
I have added plain sleep, but this solution is not a good one. So does any one know how to wait until page freezes - when auto scrolling is finished?
f you know what element you're scrolling to (the element that is at the top of browser viewport when you're done with scrolling) you can wait for the y property of a navigator representing that element to equal zero. Following is an example that you can paste into groovy console which goes to a page and then scrolls to an element by using it's id in the url (I know there is no waiting here nor the scrolling is animated but I just want to show how that property can be used to achieve want you want):
I am not familiar with protractor, so you will have to adjust the block syntax appropriately.
waitFor {
elementWeScrollTo.y == 0
}

selenium is not recognizing element in frame

In selenium web-driver, when I run this code both statements run fine and do not throw any errors i.e. it recognizes 2 frames in the user interface.
The issue is:
I see only 1 frame in user interface.
When I try to access any element, it says object not visible.
driver.switchTo().frame(0);
driver.switchTo().frame(1);
Solution tried:
Printed screenshot of both the frames to distinguish between the 2, but it prints the same screenshot for both the frames.
If you are trying to access elements in the parent page after having switched to an iframe, you will have to return context back to the default content using:
driver.switchTo().defaultContent();
and then try to access your element.

How would you verify that a certain css element on a page is a certain image with selenium

I have a page that I want to check with selenium that uses a certain background image for one element. I want to ensure that this image still exists on the page connected to the element. How would I do this with selenium. If this changes anything I am using browsermob.com to do the testing once I get it running through selenium ide.
Well aside from the suggested things on the almos duplicate issue... You could check if the property of your body element is set to the image.
By if getAttribute returns a valid value or not. Like:
new Wait()
{
public boolean until()
{
return selenium.getAttribute("ElementLocator")
+ "#class").equals("active");
}
}.wait("The menu item did not get active.",
defaultTimeOutValue);
This will wait for the attribute #class to have the value "active".
Or simply use an If statement after you are sure that the page got loaded.
Hope this helps,
Cheers,
Gergely.