Storing dynamic text in Selenium - testing

I'm new to Selenium and had the following question about storing dynamic text...
In our web application, when a function is performed (i.e. transfer), a confirmation message is displayed (i.e. "function is completed. The reference number is #12345". The ref number is then displayed in a list with other ref numbers on another page. As part of my test, after the ref. number is generated, I would like to select from the list the ref number that was just generated.
Example
1 create item.
2 confirmation message displays
3 save ref number
4 navigate to other page which contains list of ref #s
5 select item from list that was just created (select using ref #)
Question: How do I save the ref number from the confirmation message so that I have Selenium select that number from the list of ref #'s?
Thanks,
D

Find out the identifier (CSS/XPath/etc.) of the UI element that displays the reference number, and then use the relatively getText() command. In Java,
String text = selenium.getText("your_identifier");

Related

How to Select Choices input field having same class, type, Xpath everything is same

I have two input fields to enter choices which have same class, type. Id is different by it is dynamic and create on run time so i can't use id.I used indexing ,it's not working properly.
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][1]")).click();
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][1]")).sendKeys("Iphone 6");
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][2]")).click();
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][2]")).sendKeys("Iphone 7");
I used indexing in given image link.
click link to view code in organized way
Index 1 works in this case but unable to find index 2.
Given inspected html code is below of input field 1 and field 2
Field 1
Input field 1 image Xpath link
field 2
Input field 2 image link
If these two inputs are always in this sequence (so the first input is always first and second always second)
You can use:
driver.findElement(By.xpath("(//input[#type='text'][#placeholder='Provide a response entry that customers can select'])[1]")).click();
driver.findElement(By.xpath("(//input[#type='text'][#placeholder='Provide a response entry that customers can select'])[2]")).click();
At the same time I have corrected the syntax in indexing
Building on #Anand 's answer, you can simplify a little:
WebElement button1 = driver.findElement(By.xpath("(//input[#type='text' and #placeholder='Provide a response entry that customers can select'])[1]"));
WebElement button2 = driver.findElement(By.xpath("(//input[#type='text' and #placeholder='Provide a response entry that customers can select'])[2]"));
I think it's a little easier to read using and instead of stacking brackets.
I use it similarly for widgets:
WebElement header = driver.findElement(By.xpath("//div[contains(#class,'panel')]/div[contains(#class,'panel-heading') and text()[contains(.,'News Feed')]]"));

Oracle APEX 5 Dynamic Action upon page load event does not work. What am i doing wrong?

The program basically aims at retrieving some fields of a record and processing and displaying that on a textbox of static content region in apex 5
My database: LCD_MONItOR table
Interface :
PLSQL code that is supposed to execute on page load event.
Declare
lcd_id LCD_Monitor.LCD__NO%TYPE;
tag LCD_Monitor.ASSET_TAG%TYPE;
pp LCD_Monitor.PURCHASE_PRICE%TYPE;
sal LCD_Monitor.SALVAGE%TYPE;
ls LCD_Monitor.LIFE_SPAN%TYPE;
accm LCD_Monitor.ACCUMULATED_DEP%TYPE;
netbook Number;
currDep Number;
Begin
select LCD__NO, ASSET_TAG, PURCHASE_PRICE,SALVAGE, LIFE_SPAN,
ACCUMULATED_DEP into lcd_id, tag, pp, sal, ls, accm from LCD_MONITOR
where LCD__No='40';
:LCD_NO:=lcd_id;
:CURR_DEP:= (pp-sal)*(1/ls);
:TOT_DEP:= (pp-sal)*(1/ls)+accm;
:NBV:=pp-(pp-sal)*(1/ls)+accm;
End;
PS: I have returned the values to the textboxes in 'Affected Elements' Section in the properties.
But when the page is loaded, no values appear in the textboxes. Any help would be appreciated.
I'm not sure if I understood correctly what exactly are you doing. If you need just fill items with data, create a before header process (in Page Designer mode, it is in Pre-rendering -> Before Header. Write your code there, it should be enough.
If you want to do it in Dynamic Action (I wouldn't recommend this way), you need to create a Dynamic Action with Event - Page Load, which will contain a True Action with properties: Action - Execute PL/SQL Code, PL/SQL Code - your code and Items to Return - LCD_NO,CURR_DEP,TOT_DEP,NBV
But make sure your items really have such names, because by default APEX creates items with names like P10_LCD_NO, where 10 (for example) is a number of the page.
Instead of directly assigning a calculated value to the textfields items, I assigned them to a variable first then assigned variables to the items i.e
Before
:CURR_DEP:= (pp-sal)*(1/ls);
:TOT_DEP:= (pp-sal)*(1/ls)+accm;
:NBV:=pp-(pp-sal)*(1/ls)+accm;
Corrected
currDep:= (pp-sal)*(1/ls);
:CURR_DEP:= currDep;
tot:= (pp-sal)*(1/ls)+accm;
:TOT_DEP:=tot;
netbook:=pp-((pp-sal)*(1/ls)+accm);
:NBV:=netbook;

Need to capture ID after clicking on submit button

I am using selenium with java and In my application , whenever I click on submit button, system generates random ID, I need to capture that ID displayed on screen(a div) and then put in other field to ensure, all fields are filled and we are able to edit as well.
The simpelst way is this:
Create a variable that will contain the id:
String myID;
After id is created you need to capture the text in the filed:
myID = driver.findElement(By.id(".....")).getText();
After this, the ID will be saved in myID.
to see if it worked, run the following line:
System.out.println(myID);
If the output in the console is the same as in a generated ID field then all worked correctly.

How to identify individual controls within a search result using Selenium Webdriver?

I have a list of search results in the following link and would like to know on how can I identify the individual controls using dynamic xpath
http://www.bigbasket.com/cl/fruits-vegetables/?nc=nb
I'm able to get the list of product names displayed using the below line
List<WebElement> productResults = browser.findElements(By.xpath("//*[contains(#id,'product')]/div[2]/span[2]/a"));
I'm able to print the product names displayed in Page 1 using the below code, but however the list size is not matching with the list of results displayed in Page 1 so which I see blank lines in between when printing
System.out.println(productResults.size());
for(int i=0;i<productResults.size();i++){
System.out.println(productResults.get(i).getText());
}
Also I tried to locate the individual controls such as Qty text box, Add button in a similar like how I located the product names but the list count is not matching so which I cannot specify the quantity, add the required product to the cart.
Could you please help me with this one?
The first step is get only the visible itens (that is displayed), sou you can use this xpath:
"//*[contains(#id,'product')][not(contains(#style,'display:none'))]/div[2]/span[2]/a"
Now, you need to return the main iten div, that allows you to acess other functions. You can get the tag parents in this way:
"//*[contains(#id,'product')][not(contains(#style,'display:none'))]/div[2]/span[2]/a/../../.."
The elements that you recieve in this last XPath have all html itens that you want, as set quantity, select the dropdown etc. You can acess each using a findElement() in each IWebElement of the list. Example:
List<WebElement> productResults = browser.findElements(By.xpath("//*[contains(#id,'product')][not(contains(#style,'display:none'))]/div[2]/span[2]/a/../../.."));
for(WebElement element : productResults ){
IWebElement quantityInput = element.findElement(By.XPath("//input[contains(#id, '_qty')]"));
string quantityValue = quantityInput.getAttribute("value"); // if you want to know the current value. YOu can also parse it in an int
IWebElement addButton = element.findElement(By.XPath("//a[contains(#class, 'add-button')]"));
// etc to all elements inside element.
// Remember: Element is yout complete card of the item, that contains Value, name, image, buttons and all it.
}
Sorry for some Java syntax error. I am not a Java developer / tester. My piece of cake is C#.

Accessing Session State in query

I Have the following URL
.../ords/f?p=1575:31:12296330498768::NO::CONTRACTID:2
And as you can see I have set the session state of CONTRACTID to 2.
I want to acces the value of CONTRACTID in the following SQL:
SELECT
CON_CONTRACT.CONTRACTDATUM AS CONTRACTDATUM,
CON_CONTRACT.BEGINDATUM AS BEGINDATUM,
CON_CONTRACT.EINDDATUM AS EINDDATUM,
CON_KLANT.NAAM AS KLANT,
CON_VERKOPER.NAAM AS VERKOPER
FROM CON_CONTRACT, CON_VERKOPER, CON_KLANT
WHERE
CON_VERKOPER.VERKOPERID = CON_CONTRACT.VERKOPERID AND
CON_KLANT.KLANTID = CON_CONTRACT.KLANTID AND
CON_CONTRACT.CONTRACTID = :CONTRACTID
I reference the Session state using :CONTRACTID as per the documentation
When accessing the report with the above SQL I get the following error
ERR-1002 Unable to find item ID for item "CONTRACTID" in application "1575".
Unexpected error, unable to find item name at application or page level.
And the following Technical Info
is_internal_error: true
apex_error_code: WWV_FLOW.FIND_ITEM_ID_ERR
error_backtrace:
----- PL/SQL Call Stack -----
object line object
handle number name
0x148b83330 556 package body APEX_040200.WWV_FLOW_ERROR
0x148b83330 607 package body APEX_040200.WWV_FLOW_ERROR
0x148b83330 911 package body APEX_040200.WWV_FLOW_ERROR
0x14b2992c0 2607 package body APEX_040200.WWV_FLOW_META_DATA
0x14c01ff10 3334 package body APEX_040200.WWV_FLOW
0x14c01ff10 4860 package body APEX_040200.WWV_FLOW
0x14c0d60c8 249 procedure APEX_040200.F
0xa04c0228 2 anonymous block
I've tried replacing :CONTRACTID with V('CONTRACTID') and NV('CONTRACTID') but that didn't do anything
CONTRACTID have to be an application item or page item. You can't just pass any string in URL as identifier and use it in query. To create page item:
open desired page (page with query in your example)
click + sign (if you are working in Component view mode) in the Items section
give a name to your item
if you don't need to show item on a page, you can make it hidden (Display as - Hidden in the item properties)
To create an application item go to Shared Components -> Application Logic -> Application Items and create an item there.
After creating of a page item or an application item you can use their names in URLs and in report queries. The main difference between application items and page items - application items are accessible in the whole application, page items - only on their pages.