How to store Dynamic Id while using Selenium Commands? - selenium

I want to know the process how to store Dynamic Id in my test while using Selenium commands.
Problem:
I have actually on the page where the textarea I want to focus within a test. It has the id like this: id="txt_00092" and it's generated by db auto increment.
It's a comments textarea. Let's say in my test I add a comment over some post. So if I run this test again this becomes 00093. This is where I have a problem as to how to store this dynamic handling in my test.
I hope you understand where I am stuck.

I didn't understand fully your problem. Put down the problem with the ID for know and tell us what is the purpes of the test: Check if the text was fully submited? if so you can type and check if the last(or first, depend on your query oredeing, i.e Asc/DESC) div/td/whatever contains the text.
If you need to chek the ID it's a littel problem becuse here we need to breack the string and do that with JS it's tricky. Hope i help you.

When the Xpaths are dynamically changing, using Xpath this way might work for you:
[starts-with(#id,'txt_0009')]

Related

How to set using tag and id as default for Katalon Studio record function?

Currently the record function in Katalon studio uses all possibilities to identify an element (i.e. tag, id, name, class, text and full XPath). For some reason the full XPath always fail to identify an element in actual testing, and text on element is something that changes a lot and does not matter to the testing in most case. Currently I need to manually unset the unnecessary identifier after each record. Is there a way I can tell the record function to use only tag and id to identify an element?
I found this answer from Katalon Forum. So as they said, this features will be implemented in later releases.
https://forum.katalon.com/discussion/4368/how-does-katalon-studio-decides-which-identifier-to-be-used-while-automating-tests#latest

How to know the webpage is using dynamic id

For test automation, how can we know if the webpage is using a dynamic id. Here, I don't mean how can we get the dynamic id. Instead, I want to know how to use API, e.g. Selenium API, to know if the web element is using dynamic id.
For example, some ComboBox's id will not change when we select its option. But for other ComboBox's id, it may change as selecting its option.
So, do we have a way to detect, or to know, if the web element in the webpage is using a dynamic id?
No, unfortunately you have no way to discover if and id will change using Selenium.
The only way an HTML element could have its id attribute changed is through JavaScript code. And the only way to know if a piece of JavaScript code changes an id is to execute it. (In other words, you can't, ahead of time, know the id will change. You can only know that JS code changes an id when it actually changes the id, and by this time, of course, the changing already happened.)
If, on the other hand, you want to know if an element had its id changed, you can, before the change takes place, get a hold of it through Selenium (using driver.findElement()) and then keep checking if its attribute changed. (If the WebElement instance becomes stale in the process, you could, as a workaround, add a class with a unique name to it, and then find it back using by.className() - since you may not find it again by its id like before, as it could have changed.)

Access to the page body from selenium

I want to create Selenium test that posts web form, but one field is riddle from the list. Riddle gets randomly. Answers are known. I should fill answer in field.
Is it possible to access in Selenium test to the page source code to define current riddle and place in the input field answer?
Certainly. For example, in Ruby bindings it'd be #browser.page_source

i18n testing using selenium

Have any one used selenium for testing i18n !
Does Selenium provide any kind of I18N/L10N support? Is it possible
to verify text based on message keys from a resource file? What
about checking numbers and dates that might have a different format
because of L10N?
I am also interested in the correct approach for this issue. Where I work, we usually use the ids to verify certain page or field. But, sometimes you might need to verify some text, which could be using i18n.
Try the following:
If you have a selenium-testing module, have the module where the bundle is placed as a dependency. And then define a ReloadableResourceBundleMessageSource in the xml. And than setup the test following this code: https://stackoverflow.com/a/6251478/521754
Hope that helps!
Cheers!

Is any way to get captcha value and store it in a variable?

I am Using Selenium RC in C# My application has 3 Captha image in Different registration pages. i have a Huge script i will run it on night hours(when i am off). Hence i feel it will be better if i can capture the last displaying captcha image value and store it in to a variable so that i can input on the relevant field. Is it Possible ?
A Captcha cannot be automated that easily. That is why they were invented!!
Alas... You can use code hackers and Image Recognition patterns and scripts. It is called OCR. http://en.wikipedia.org/wiki/Optical_character_recognition
I will not write more about this as i wont encourage others for hacking ideas. But... First: Google is your friend. Second: In my testing environment we used a captcha with a static value. And then before it went live we removed set it again for the algorithm.
Gergely.
Have a hidden field (with a non-obvious name) that contains a strongly encrypted copy of the text used in the captcha then on your selenium test system decode it using the private key?
For testing purposes you will need to send the captcha value in a machine readable manner, by sending it as an additional field. You would then need to remove the field after the tests are done.
Make use of the 'input' tag with type 'hidden' in-order to handle Captcha.
JavascriptExecutor js = (JavascriptExecutor) driver;
//Set the captcha values using setAttribute
js.executeScript("document.getElementsByName('xxxx')[0].setAttribute('value', 'xxxx')");
driver.findElement(By.name("xxxx")).sendKeys("xxxx");