Need to capture ID after clicking on submit button - selenium

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.

Related

Apex, Dynamic action, Confirm action, not picking up correct text - what am I missing?

I'm obviously missing something and hoping someone might be able to help.
I've an Interactive Grid, and a button.
When the button is pressed the dynamic action on the button has 2 steps.
Action 1 - Execute Javascript to take a value from one of the IG cells and put it into a page item.
Action 2 - Confirm Action - Are you sure you wish to delete &P10_JOB_ID.
I've made the page item, &P10_JOB_ID, visible and I can see the value has correctly been changed to the value from the IG.
I write P10_JOB_ID into a database table - I get the correct value
But the confirm message isn't picking up the correct value from P10_JOB_ID.
Namely it uses the value in P10_JOB_ID when the page starts, but then as I move around the IG pressing the button and changing the value of P10_JOB_ID, the text in the confirm message never changes.
Can anyone suggest what I might have missed, I'm baffled.
Thanks a lot
Substitutions like &P10_JOB_ID. are made when the page is rendered, not dynamically, so reflect the value at time of page load.
You will need to use Javascript to perform the conform action, something like:
apex.page.confirm ('Are you sure you wish to delete ' + $v('P10_JOB_ID') + '?', 'DELETE');
$v is an APEX Javascript function that returns the current value of a page item.
I used 'DELETE' as an example of a request value; you may want to do something different here.
Ok - having the setting of value and confirm as 2 separate actions is what causes the problem.
As per fac586
That is the expected behaviour. Static text substitutions are performed once during page show processing. They are not evaluated dynamically in the browser at runtime as values change.
Drop the second action and extend the first to display the confirm dialog using the apex.message.confirm JS API method, accessing the item value using the $v shorthand method.

TestCafe does not write in text input field

I'm using TestCafe for test automation of a web application based on the Wicket framework. I try to type text into a text input field ... well, actually it is a dropdown list, where a text input field appears, so that the user can search for certain codes. The HTML fragment is as follows:
HTML fragment
And here is the corresponding screenshot (text field above "001"):
Text input field with dropdown
The user can type some characters and the list below is automatically filtered (I did this manually):
Text input field with some text
My TestCafe test tries this:
.click( productcodeList )
.expect( productcodeInputField.visible ).ok()
.click( productcodeInputField )
.typeText( productcodeInputField, 'ABW' )
i.e.
Click on the drop down list.
Assume that the text input field is now visible (works fine).
Click on the text input field (this should not be necessary, since typeText() is supposed to do this anyway).
Type the text "ABW" into the text input field ==> This does not work.
I'm sure that my Selector works, since the assertion (expect) is successful and when I debug the test run after the second click (on the text input field), I see the following:
TestCafe screenshot
I.e. the cursor is directly on the text field, but somehow TestCafe cannot write the text into the field.
Some additional information: The Selector for the input field is created as follows:
productcodeInputField = Selector('span').withAttribute('class', /select2-dropdown.*/ ).child('span').withAttribute('class', /select2-search.*/ ).child('input').withAttribute('class', 'select2-search__field' );
More information: I'm using the same logic on the same page:
kurzbezeichnungField = Selector('input').withAttribute('name', /.*aeAbbreviation.*/);
...
await t.click( kurzbezeichnungField )
.typeText( kurzbezeichnungField, 'xxxWWW' )
and this works fine.
Node.js version: v10.16.3
Testcafe version: 1.5.0
This issue looks like a bug. However, I cannot say it precisely without an example that demonstrates the problem.
My team would really appreciate it if you share your project or sample to demonstrate the issue.
Please create a separate issue in the TestCafe github repository using the following template and provide as much additional information as possible.

Using send_keys() on a search/filter input field does not filter results in table

There is a table with a list of users and their email on a webpage. At the top of the page, is a search/filter input field that allows the user to type an email or username and filter for the result as he/she is typing.
The problem: However, when I use the send_keys() method instead of doing this manually, nothing is filtered in the table view.
This is happening on the Safari browser on the iPhone 7 Plus (real device, not simulator). Some other information:
iOS version: 12.2
Appium version: 1.13.0-beta.3
Selenium version: 2.53.1
Programming language: Python 2.7.15
In addition to send_keys(), i've tried to use set_value(), i've also tried to execute JS and setting the attribute value, and also tried to send key for each character (in a for loop with a delay between each character).
I'm expecting for example, element.send_keys("test1000#test.com) to filter the table view on the web page so that the only user that is displayed has the associated test1000#test.com email as it does when I go through the site manually.
In actuality, send_keys() does not do that and nothing in the table view gets filtered.
Any help or guidance would be appreciated!
Explicit wait for table to get populate in DOM
sendKeys search String and additional key Tab
textbox.sendKeys("test1000#test.com"+Keys.TAB)
Explicit Wait for filter to get applied and table to get refreshed.
find elements for the newly populated table with applied filters.

How to handle Xpaths which changes dynamically every time?

I am writing selenium web-driver script. The scenario of script is:
1) Login in www.yahoomail.com
2) Sign-in successfully.
3) Click on "Compose" button
4) Enter email ID in "To" Field.
5) Enter subject in "Subject Field.
6) Enter Email Body in "Text" Field.
7) Click on "Send" button.
Using Firepath, I have taken xpath of fields mentioned in "Compose" page.
But every time when I open Compose page, this xpaths changes dynamically.
Below is the script I am using:
WebDriver oYahoo = new FirefoxDriver();
oYahoo.get("http://www.yahoomail.com/");
oYahoo.manage().window().maximize();
oYahoo.findElement(By.xpath(".//*[#id='login-username']")).sendKeys("abcdefasdf#yahoo.com");
oYahoo.findElement(By.xpath(".//*[#id='login-passwd']")).sendKeys("sfgas234#123");
oYahoo.findElement(By.xpath(".//*[#id='login-signin']")).click();
oYahoo.findElement(By.xpath(".//*[#id='Compose']/button")).click();
oYahoo.findElement(By.xpath(".//*[#id='yui_3_16_0_1_1448364357109_2222']")).sendKeys("abcdefgh#gmail.com");
oYahoo.findElement(By.xpath(".//*[#id='subject-field']")).sendKeys("Hi This is my first automated mail");
oYahoo.findElement(By.xpath(".//*[#id='yui_3_16_0_1_1448364357109_1966']")).sendKeys("Hi This is my first automated mail");
oYahoo.findElement(By.xpath(".//*[#id='yui_3_16_0_1_1448364357109_2465']")).click();
oYahoo.quit();
What we can do so that it will take Xpath dynamically? Do we need to map those things in some class ? do we have to write any other class for "Compose" pop-up?
If "Yes" then how we can do it ?
Try to observe a common pattern that is repeated everytime. Either an id prefix or class prefix, anything.
Then use the following selector in your By.xpath(..) function.
//*[contains(#id,’your-common-pattern’)].
I worked on a project where class names where random each time the page was generated and the unique way i found to get those label/input/.. is i used the nth-child() function with the css selector. The thinking method is like : I want the 3rd input from the 2nd row of the 1st table.
checkout this fiddle to understand what i meant.
https://jsfiddle.net/8v150af1/

How to force the parse (only one time ) of a Dojo's button [Err: widget is already registered]

I have a function which adds a button to a div "dettaglio_utenti". After calling the function with this instruction
tab+="<button data-dojo-type='dojox.mobile.Button' id='apri_mappa' onClick=\" location.href='tel:"+telefono+"'\">apri mappa</button>"
var vText = document.getElementById("dettaglio_utente");
vText.innerHTML = tab;
require(["dojo/parser"], function(parser){
parser.parse(vText);
});
It works only the first time that I display the page. The second time the button is not parsed and I see this error in the browser console: dojo/parser::parse() error Error: Tried to register widget with id==apri_mappa but that id is already registered
When you display the page for the second time, the first page must still be part of the dom. (Maybe this is a worklight feature, single page app?). So when dojo parses the second page it gives the error because the button with that id has already been created.
I don't believe preventing the parsing of the button a second time will accomplish what you need. I think your options are:
Destroy the widgets from the first page.
If you don't need an id on the button, you can omit it and Dojo will create an id that won't collide.
If you need the id, you can or use a counter when emitting the id of the button.
id='apri_mappa_' + i where i is the counter.
Only knowing what you wrote above, I think the order of preference is 2,1,3.
EDIT - How to destroy a widget
require(['dijit/registry'], function(registry) {
registry.byId('apri_mappa').destroy();
});