What are the attributes for identifying elements in watir-webdriver? - automated-tests

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.

Related

What to use: Xpath or CSS selector while scraping Linkedin?

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")

Is there an official complete table with all CSS properties and all possible values?

Is there an official complete table with all CSS properties and all possible values? I'm looking for all possibilities, including the latest "CSS4"/modules.
I'm looking for the all encompassing version of https://www.w3.org/TR/CSS21/propidx.html (but that one only has CSS 2.1).
This lists out all properties, but doesn't include all possible values on the same page: https://www.w3.org/Style/CSS/all-properties
Full CSS catalog with information about possible values https://websitesetup.org/wp-content/uploads/2016/10/wsu-css-cheat-sheet.pdf
And this is also great: https://www.smashingmagazine.com/2009/07/css-3-cheat-sheet-pdf/
-> PDF https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/d7fb67af-5180-463d-b58a-bfd4a220d5d0/css3-cheat-sheet.pdf
You can use the official W3 specifications. These are (mostly) respected by all major browsers.
For a more simple and user friendly but incomplete list see css-tricks almanac.
Apparently, there's no such official list.
However the current work is conveniently located in a single w3c/csswg-drafts repository (https://drafts.csswg.org/ and https://drafts.csswg.org/css-2018/ help make sense of the list) and the spec markup is designed to be machine-readable. So if you're looking for a fun way to spend a weekend and learn a bit about the CSS specifications, you can try to generate one yourself!
Alternatively, you could ask around to see if the person who maintains the script to generate https://www.w3.org/Style/CSS/all-properties is willing to share it with you.

Chrome Element clicking problems, pageFactory framework solution

I am having issues with Chrome throwing element stale, element not click able other element would receive click. My question more so has to do with pageFactory framework.
Given that chromedriver has these issues I would need to rewrite the selectors with offsets and other functionality to make it able to be click able correctly.
Should I make new xxxxPage.class's specifically for chrome? Or should I just incorporate all the chrome fixes into the current xxxxPage class, knowing that it will most likely work in firefox?
Or I can make a copy of the "SignIn" function for example with chrome fixes.
Basically what is the best way of keeping your final test code clean, with these changes?
Thanks
From my perspective the page object should describe the page elements and not should be depends to the concrete driver implementation. I suggest to implement the helper common class that contains some common methods and then the specific classes that contains the specific implementation per browser. Then in your page object you will call the one common function which will call the required to the driver class/method. In other words you will encapsulate the specific driver behaviour in the specific classes and the common class will decide what specific class will called.

use xpath or css selector to parse all the element in a hybrid mobile app

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.

Selenium IDE - plugin to find alternate ID selectors?

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

Resources