Is it possible to capture ItemId property in extjs using selenium? - selenium

I have to test an Extjs application. But the id is dynamic so there is no way to capture it. But developers have been adding another property as itemId to elements. Is there a method to capture that itemId using selenium?

You can execute JavaScript code on the page using Selenium to get the dynamic ID.
In this code you can use Ext.ComponentQuery for getting exactly the ExtJS component you want. Next using function .getId() you can get the dynamic ID.
driver.execute_script("Ext.ComponentQuery.query('#myPanel').getId()")
You can read more in my other A to the similar problem
https://stackoverflow.com/a/41718879/1768843

Related

Extracting A Value From An Inline JS Script Tag With RobotFramework

There is some inline JS that runs at the top our website. It contains some name value pairs that it pulls from the webpage. I am writing tests with robot framework to assert these exist and have values. A small extract of the JS looks as follows:
siteId':'1133','offerId':'1228','productId':'549','
I am able to assert the existence of the names using the xpath locator as follows
page should contain
element xpath=/html/head/script[contains(text(),"siteId")]
With robot framework and Selenium Library I am asserting that the names exist using the page should contain element keyword and this works perfectly.
Now I need to extract the value, so '1133' in the example above.
I have been using the get element attribute keyword which has worked well when grabbing values in other places in the DOM. But doesn't seem to work for this case. I keep getting none as the value.
My xpath probably needs to written differently for me to be able to extract the value from it, but i'm not sure.
All help or ideas are greatly appreciated.
You should be able to get the contents of the script tag by fetching the value of the innerHTML attribute. reference
I am not familiar with robot framework, but based on the info you provided, I suspect using get element attribute with innerHTML will return the script tag's contents as a String, which you could then match using a regular expression.

how to reach to table content which is coming from ajax in codeception?

I want to click the button which is in table,And table is coming from jquery ajax.
I have tried
$vic->click("Approved",Locator::href("//*[#id='users']/tbody/tr[1]/td[5]/a='Approved'"));
Link or Button by name or CSS or XPath element with 'Approved' was not found.
It looks like you are using module which does not execute client side Javascript code.
If you want to test that code, you must use WebDriver module which tests websites using real browser.
Like #Naktibalda said, you should look at the WebDriver docs. You can do something like this:
$I->waitForElement(['id' => 'myButtonFromTheAjaxCall']);
$I->click(['id' => 'myButtonFromTheAjaxCall']);
Also, I would use a unique ID on that button coming over from your AJAX call if you can rather than using XPath, it's quicker I think.

Create a Reusable method to Verify list elements by Selenium WebDriver

I am new to this site and don't know how things show up here. I was reading the post from below where String array is being used to ListwebElements.
Verify list elements by Selenium WebDriver
String[] expected = {"GRAM", "OUNCE", "POUND", "MILLIMETER", "TSP", "TBSP", "FLUID_OUNCE"};
I am trying to do something similar using String Array trying to get different buttons on a UI page. I want to make this method reusable by changing the "expected" list per test. Does anyone know how you would make this method Reusable?
In my case, "expected" list is different each time depending on a page.
I would suggest to use the custom annotation for reusing purpose. Please see the example here.
If you are using JUnit you can also use parameterized test

Locating elements in selenium IDE

I have tried to locate button in my web app using xpath but it changes automatically each time I open selenium IDE. Is there any other way to locate it except using xpath or position? can I locate it using class name? If yes then how can I do it?
You can use xpath to find element by class name.
//*[#class='someClass']
where, someClass is the class name of your element.
Since it is your webapp, consider adding an id or a name to uniquely identify the element. It also makes the xpaths easier to write as you don't need to consider the possibility where you might be grabbing too many elements.
Answer - If by default recorded xpath are not working for your application, then you can define your own xpath for those components which should remain same throughout execution.
Please refer below URL which shows ways to develop userdefined xpath :-
http://docs.seleniumhq.org/docs/appendix_locating_techniques.jsp
Use a CSS selector. This site really helped me: http://saucelabs.com/resources/selenium/css-selectors
if it has an id on it you can just say "id=yourid"
for css it could be something like this: "css=button[class*='yourclass']" <-- that says it's a button, and that in class it contains yourclass.

How to find XPath of an ExtJS element with dynamic ID

All the elements in the application which i am testing have dynanic ID's . The test always passes when i replay it without refreshing the page but as soon as i refresh the page, The Test Fails because Id's of all the elements changes randomly and selenium cannot match the recorded id's with the new ones .
I tried to use Xpath-position, It works for some objects but in case of Dropdown list and Buttons, it dosent work!
Can anyone please tell me how to find the Xpath (Meathods in JAVA or S*elence*) of an object OR How to create a new Locator Finder for Dropdown list and Buttons
I can show the properties (Inspected by Firebug) of the dropdown which is teasing me.
properties of Dropdown :
<div id="ext-gen1345" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-last x-unselectable" role="button" style="-moz-user-select: none;"></div>
properties of Dropdown*Choice*:
<ul>
<li class="x-boundlist-item" role="option">Rescue</li>
</ul>
Please search before posting, I have been answering this over and over.
ExtJS pages are hard to test, especially on finding elements.
Here are some of the tips I consider useful:
Don't ever use dynamically generated IDs. like (:id, 'ext-gen1345')
Don't ever use absolute/meaningless XPath, like //*[#class='someclass']/li/ul/li[2]/ul/li[2]/table/tbody/tr/td[2]/div
Take advantage of meaningful auto-generated partial ids and class names. (So you need show more HTML in your example, as I can make suggestions.)
For example, this ExtJS grid example: (:css, '.x-grid-view .x-grid-table') would be handy. If there are multiple of grids, try index them or locate the identifiable ancestor, like (:css, '#something-meaningful .x-grid-view .x-grid-table'). In your case, (:css, '#something-meaningful .x-form-arrow-trigger')
Take advantage of button's text.
For example, this ExtJS example: you can use XPath .//li[contains(#class, 'x-boundlist-item') and text()='Rescue']. However, this method is not suitable for CSS Selector or multi-language applications.
The best way to test is to create meaningful class names in the source code. If you don't have the access to the source code, please talk to your manager, using Selenium against ExtJS application should really be a developer's job. ExtJS provides cls and tdCls for custom class names, so you can add cls:'testing-btn-foo' in your source code, and Selenium can get it by (:css, '.x-panel .testing-btn-foo').
Other answers I made on this topic:
How to find ExtJS elements with dynamic id
How to find unique selectors for elements on pages with ExtJS for use with Selenium?
How to click on elements in ExtJS using Selenium?
Using class names in Watir
how to click on checkboxes on a pop-up window which doesn't have name, label
I would suggest you build a xpath from any of the parent of your DIV. you may get messed if there is no immediate parent node has such one.
example,
//*[#id='parentof div']/div
//*[#class='grand parent of div']/div/div
i did even something like this,
//*[#class='someclass']/li/ul/li[2]/ul/li[2]/table/tbody/tr/td[2]/div
But still, its not encouraged to do so.