I'm using extjs, so often I need the parent's ID, or the parent's parent's ID for a selector. Is there any plugin which lets me traverse up a DOM element looking for different IDs, or a plugin which can filter out certain ID patterns? (such as ext-gen\d+).
You can use Firebug and Firepath plugin for Firefox to find the IDs
There is possibility to use XPath - it can search even element which contains something. See one of examples here: http://zvon.org/xxl/XPathTutorial/Output/example6.html
I believe you can set the IDE to search by XPath and not only by ID
There is no solution. Use CSS selectors manually and make sure you're running on >FF3.x
Xpath is unique identification of the element. Xpath works better with FF,Safari and Chrome. But it breaks in IE sometime, so in that case you can use Css selectors.You can use Firebug. Over Firebug you need to install firepath.
You dont have to consider the DOM before using XPATH generated by firepath. It is very useful if you are having the elements that have dynamic IDs.
Both Firebug and firepath are the mozilla addons.
First install Firebug then firepath.
In the Selenium IDE when you are recording something. There is drop-down menu in Target in that select XPath:Position. It will work for dynamic element and does not change.
Cheers,
Amit Shakya
Related
i want to scrape Linkedins activity posts - comments, number of views and so on.
What selenium method to choose: Xpath or CSS?
I am trying to do this with Xpath but i have hmm the strange feeling that it is changing based on profile, language and chrome version.... How to do this for general usage?
Can anybody advice?
Xpath can change with the execution of javascript or can be different on different profiles. If the only chance is using xpath, then it is ok but if there is an id or special class you should use them.
In selenium, you have multiple options to select an element by id.
driver.find_element_by_id('ember87')
driver.find_element_by_xpath("//*[#id='ember87']")
And of course you can use any other css selector and generally this is the convenient way.
driver.find_element_by_css_selector("#ember87")
driver.find_element_by_css_selector("div#ember87")
Also you can use the parent element to make selection more special and more convenient.
driver.find_element_by_css_selector("#ember72>#ember87")
How can I trace back to look at the table table-striped css code?
If you need to find anything in your solution you can do so by using the search functionality in VS. It's impossible to do anything without it, definitely one of the most used shortcuts.
Opens the window to search the entire solution for whatever it is you're after...
ctrl + shift + f
As others have pointed out, you can use <CTRL><SHIFT><F> to find the CSS class. I prefer to use this in conjunction with Dev Tools and the Elements selector.
One other thing, I see you're using a GridView. If you're working on a responsive website, a GridView will not work since it produces its own table markup. If that Is the case I would suggest using a ListView instead, especially if you're hooking up to Bootstrap.
I am currently working for a mobile UI automation testing. Our application is hybrid mobile app based on Cordova. So I am planning to use appium to run some automation tests.
One thing I need to figure out is how to find all the element in a page.
I was previously planed to use xpath to find all elements, since we can detect xpath through appium inspector. However, my colleague does not agree with me, since he wants to use css selectors as the key to find all element in the mobile app. But for appium, it does not show css selector in the inspector.
So, i am just curious which approach should be better?
Thanks
Below is my breakdown of Locators and how/why I like to use each for iOS Automation. All of this is experiential based on my work with Native iOS applications.
Giant disclaimer:
I don't know anything about Cordova. I hear there are issues that exist with UIAutomation if there are class names that aren't native. If that is the case, I suggest sticking to accessibility id and class name locator strategy.
Locators for iOS Automation
CSS Selectors
CSS Selectors do not exist in Appium.
Class Name
The closest you'd get to CSS Selectors is the Class Name selector. I don't really use them because UIAutomation gives me what I need and allows me to check for the name/text of the element in the locator strategy.
XPath
You don't want to use XPath because it's slow and flakey on iOS. (It can sometimes return an entirely incorrect element). It can sometimes cause Instruments to fail for no reason. Highly suggest staying away from XPath.
Accessibility ID
You should use this when UIAutomation fails to find the element. It's quicker than XPath but is useful when UIAutomation doesn't let you at an element (.actionSheets() is broken I think. I use this for when the action sheet is up and I need to .click() a button)
UIAutomation
You should use Apple's UIAutomation, 2 framework as it is the quickest, native solution to iOS.
The UIAutomation framework allows you to use classes and hierarchy to specify which element you want. When you use Appium, use the find_elements_by_ios_uiautomation function on your webdriver.
Example Usage here
But the example usage doesn't tell you how powerful UIAutomation really is. A common problem I ran into is trying to find all cells of a tableview when there was more than one tableview on the screen.
Find all UIACells for the UIATableview "Cart"
**Sample View Hierarchy**
<application>
<window>
<table name="Items">
<cell name="Foo, not in cart"></cell>
</table>
<table name="Cart">
<cell name="Bar. IM IN YOUR CART"></cell>
</table>
</window>
</application>
OK now to find those cells in an array:
value = '.tableviews()["Cart"].cells()'
cells = driver.find_elements_by_ios_uiautomation(value)
Extra Reading: Guide that goes over predicates and why they're awesome
Limitations for UIAutomation
If your element doesn't have a visible name. (Developers like to put invisible buttons behind "Hint Overlays" and the like.)
Suggested Solution: add an accessibility id, use the accessibility id locator.
Testing locator strategies
There's a nice place in the Inspector (provided in the Appium.app GUI) which lets you try whatever locator strategy and value you want. You should use it. It helps so, so much.
In Watir we have a grid of all elements and how they can be discovered (here). In Watir-Webdriver we do not. Is there a grid online, or a way to discover what attributes can be used on what elements?
They are pretty much the same as the Watir ones, when converting my test scripts from Watir to web driver I didn't find any that were not supported.
The class list on the API Docs http://jarib.github.com/watir-webdriver/doc/# will show you all the elements supported.
Are there any utilities that will crawl a site and determine which css rules are in use and which are not? We have a large site and a huge CSS file (--don't blame me I just got here). And, I think much of it is not being used however I'm afraid to strip stuff out just in case.
The file is confusing and difficult to manage and I think if we can trim it down by getting rid of the unused rules we will have a good starting point to go through and try to make it better.
Try the Dust-Me Selectors Firefox extension by SitePoint. It finds CSS selectors whose rules are never applied to your pages so you can remove them from your stylesheets.
https://addons.mozilla.org/en-US/firefox/addon/10704/?src=collection&collection_id=23d14a2d-b396-c08f-e9ba-b4d34691d5a9
It's an addon in Firebug.
I had the same problem a while ago (5k lines in a CSS) and found this Firefox Plugin which worked very well for me.
The Google Page Speed plugin for Firefox's Firebug addon is also a great tool that will highlight the unused CSS selectors as well as inform you which ones are poor performers.
As always though, you need to be aware that the CSS selector may not be used on "this" page but may very likely be used on another page so be careful when pruning them to ensure they are truly unnecessary.
You can use a service like Unused-CSS
This web app explores the pages of your site and builds clean CSS files