Build xpath with iFrame from jqueryui.com - javascript

I am on the https://jqueryui.com/selectmenu/ website where I am trying to build xpath for the first selector Select a speed. I build the xpath to iframe but how to reach the first selector Select a speed?
//body/div[#id='container']/div[#id='content-wrapper']/div[1]/div[1]/iframe[1]

Since your elements are inside the iframe in order to access these elements you should first switch to the iframe as described here
Also, to locate the iframe you can simply use one of the following xpaths//iframe or //iframe[#class='demo-frame'] or select by class demo-frame etc.
After switching into the ifame the xpath to select a speed is //span[#id='speed-button']

Related

How to hover over using TestCafe?

As a part of Automation testing, I want to hover over this node. which has a complex source code. You can find the code here
. Can someone please say the code which can hover using the syntax .hover(Selector(?)) using TestCafe.
Thanks in advance!
For now, you can select nodes in svg only if it's inserted into the HTML document via the <svg> tag. TestCafe does not support selecting elements in an svg that is imported from a separate document via the <object> tag.
There are multiple ways to select an element in TestCafe using Selector. To do that, you need to identify the element's distinguishing features. These might include the element's id, class, attributes, position in the DOM tree or relation to other elements. Then you need to create a Selector based on one of these features.
For more information on TestCafe selectors see our documentation.

Python Selenium edit text content of specific javascript element in specific iframe

I am trying to use python selenium to change the text in a specific JS element.
I started out by attempting to simply execute the script using the following:
driver.execute_script("document.querySelector('#cssSelector').textContent='{}'".format(text))
However, unfortunately, this returns null
When looking into the JS the selector is in a specific iframe so I have tried to select the iframe but this has not yet worked:
driver.execute_script('''var element=window.frames['iframe'].document.querySelector("[id='cssselector']"); element.textContent='{}'".format(text))
This code also returns undefined as it cannot find the element.
Is there a better way to do this? thanks

What are the reasons or benefits of using dynamic id in each and every html elements

Recently I found one website in which, all the html elements have dynamic id's.
This website is very popular in the world.(www.quora.com)
Now I just want to know that what is the reason to do this type of stuff for all the html elements which are available on web pages.
I actually don't see that in the Quora source served to me. There are a lot of ids but they are all in <g> elements that form part of svg graphics.
Looking at the browser's view of the (signed in) homepage via Chrome's inspect tool I only see four ids.
In general if I saw ids on most/all elements in a page I'd expect a framework being used to generate the HTML.
useally its a side-effect of the framework people are using for the website.
The reason it is used at all tho is because a single webpage can't have duplicate id's, this because if this would happen the browser would not know witch element to pick with the givin id. when you try this out yourself you would notice the browser only picking the first element with the given id. the other elements with the same id will be ignored or the code will not run at all.
A solition to this problem is dynamicly adding the id's so you can reference to those elements without the risk of some elements being ignored.
By dynamicly adding these id's you can be certain that every id will be diffrent from each other.

What could I use to generate names of element locators?

I need to generate names of element locators for a project I am currently doing using Selenium IDE. I can use xpaths, css or dom to find elements and use them to generate names of elements. Can anyone suggest what to use to extract meaningful names from css, xpath or dom? For example, I can use
//li[#id='item1c4994198e']/div/div/a/img
as my xpath to get to the element and use the id attribute to generate a name for the element.
#Vaibhav: Fetching elements with right locater is the Heart of Selenium. Now here are few things which you should always remember.
Never make your script dependent on Absolute Xpath .(i.e path from source like /html.body......). Try to use plug ins like firebug to generate Xpath.. You may also come across a situation where the path generated by firebug may not detect your desired element on the page so option is to use relative path. If you still need more info on it ..you can follow below links
http://www.toolsqa.com/selenium-webdriver/xpath-firebug-firepath/
It is always better to use relative xpath, if you are unable to get the element locator then go for absolute xpath, DOM is limited to Selenium RC only.

How show specific content inside iframe on another site using JS/jQuery

I need to target a specific area on another site and have that module fit to the size of the iframe. I would figure jQuery might be used best targeting a div id or class that the content I need is wrapped around it. Any ideas?
Try:
$('#id', window.frames['frame-name'].document)

Categories

Resources