My query is that - I have my images on webpage- a logo or say navigation bar i can store as an image. Can i test using selenium presence of these images on a webpage when loaded along with the position of the image on page.
What my issue is that i need to actually look at image objects in HTML and also may be images not in HTML but they are partial screenshots of webpage which i want to match. This test will help me pick alignment issues - in case my navigation bar is now going to second row i can match with previous stored image to check.
Thanks
VB
An example on how to check if a particular image is present:
In this page:http://www.google.ie/firefox?client=firefox-a&rls=org.mozilla:en-US:official
Selenese command
Command: verifyElementPresent
Target: //td/table/tbody/tr/td/table/tbody/tr/td/img[#src='/images/firefox/Fx4Launch.png']
Hint: If you want help to get the XPath for a particular element I recommend you using a plugin like Firebug (http://getfirebug.com/)
Put an extra "\" in the beginning of the xpath copied by Firebug, otherwise selenium do not find the element.
You can verify that an image is at a location like so:
verifyElementPresent //div/p/img
This example uses XPath to locate an <img> element that follows a <div> and <p> tag.
But verifying that a screenshot is the same as the rendered page? You're talking about a completely different problem, which is image recognition. Selenium is a tool for automated acceptance testing.
Related
I am using Selenium IDE to conduct testing my website.
Please refer to the above image. I have 2 windows one over the other and I need to get the xpath of the 2nd footer that is the last in the image.
When I use Selenium it picks but does not work as expected. In a situation like this how do I know the xpath and which to use in Selenium.
Thanks
You can do this to access the 2nd element with that xpath
driver.find_element(BY.XPATH,"(//div[#class='footer'])[2]")
If you need any of those individual values.
I would use link_text since they all have different text values and are all of a tags.
driver.find_element(BY.LINK_TEXT,"Upload")
Let's say we're working with an element in chrome. And it's not clear whether it's inside an iframe or not. You right-click the element > copy > full xpath.
This shows the full xpath but only from the point where the iframe starts. Is there any way to copy the full xpath that includes the parent frame as well?
I'm basically trying to see if there's an easy way to find out whether an element is present inside an iframe instead of visually scrolling through the entire HTML code searching for an "iframe".
I've searched for browser extensions but didn't find anything that can "highlight" the iframes. I've tried highlighting them manually as well by searching for each frame and hovering the mouse on the objects inside it. It's not a good method for finding out whether or not an object is inside an iframe.
Is there a way to get the full path of an HTML element (including the path from the root HTML tag)?
I am writing an automation script for an avatar upload module with the following CSS locator:
input[accept="image/png,image/jpeg,image/gif,image/bmp"]
I am using Robot Framework's Wait Until Element Is Visible keyword to look for the locator above but is unsuccessful with the error:
Element 'css=input[accept="image/png,image/jpeg,image/gif,image/bmp"]' not visible after 30 seconds.
Increasing the timeout also doesn't work. Using the same in Chrome Dev Tools would successfully find the element. My guess is that the commas/slashes are messing with Robot's locator parsing. My question is: What is the correct way to write the locator?
Though present in the DOM, an element may not be visible/rendered. This is very often the case with file upload input elements - the UI renders something different, a button, div that had applied styling and fits in better with the overall design.
Thus a check is it visible will rightfully fail. Change your pre-usage approach to validate the input is in the HTML - this is actually the same as what you did in the browser's dev tools - with the Page Should Contain Element keyword, and proceed on success.
There is no problem with the CSS locator your are using. Maybe the element is in another iframe?
I'm working in selenium with Firefox browser.
The Html code shown in View Source (CTRL+U) is different from the html code i see when inspecting the elements in Firefox.
When i run the driver.getPageSource() i only get the View source (CTRL + U) codes.
Is there is any way to access the Inspect element code instead of View source code?
I think your question is answered here.
The View Source html is what is sent by the server. I think of it as compile time html, or the initial state of the DOM.
The Inspect Element html could have been updated by ajax responses or javascript so will not necessarily be the same. I think of it as runtime html, or the current state of the DOM.
The GetAttribute() method queries the current DOM element state. You can return a particular html attribute value directly
webElement.GetAttribute("class")
or get the whole html string.
webElement.GetAttribute("innerHTML")
There are some fundamental difference between the markup shown through View Source i.e. using ctrl + U and the markup shown through Inspector i.e. using ctrl + shift + I.
Both the methods are two different browser features which allows users to look at the HTML of the webpage. However, the main difference is the View Source shows the HTML that was delivered from the web server (application server) to the browser. Where as, Inspect element is a Developer Tool e.g. Chrome DevTools to look at the state of the DOM Tree after the browser has applied its error correction and after any Javascript have manipulated the DOM. Some of those activities may include:
HTML error correction by the browser
HTML normalization by the browser
DOM manipulation by Javascript
In short, using View Source you will observe the Javascript but not the HTML. The HTML errors may get corrected in the Inspect Elements tool. As an example:
With in View Source you may observe:
<h1>The title</h2>
Whereas through Inspect Element that would have corrected as:
<h1>The title</h1>
getPageSource() always returns the markup obtained through View Source.
I have an html page that has a small piece of JavaScript that further embeds an HTML form in a div tag (this div is identified by an ID).
I want to use Selenium IDE to test the form. I recorded a basic test to test the embedded form but Selenium seems to be failing. It cannot find the elements or the text.
I got the source of the parent html page but it does not have any Form html. Firefox allows you to see the Form html by going to 'This Frame->View Source'. The embedded html is whole html page not just the form - I mean it starts and ends with <html> tag
I was wondering how could I test the embedded form using Selenium IDE ? I searched a lot and found 'SelectFrame' but all the examples on the web include Java code (that I do not wish to get into) as opposed to plain HTML (I would like my test to be plain HTML Selenium test cases and would like to keep it simple).
Also, I doubt if 'SelectFrame' is going to help as the form gets embedded in a 'Div' tag and not in the frame.
Any help is greatly appreciated.
Thanks
you have a frame and frame have some name, please use this and let me know
selectFrame | frame name |
verifytext | text
selectWindow | null - this for release the frame
please show me once your script so that I will help you futher
use
driver.switchTo().frame("marco");
replace "marco" with your own frame name