How to verify Local language in UI using Selenium - selenium

I am new to testing and have a question about how can we verify the local language using Selenium. Suppose that I have some link which lets me choose the language, so if I choose a language how can I verify that?

By anything on the page! Let's assume our page is only made of one element, either
<div>
It's time to kick ass and chew bubble gum!
</div>
or
<div>
Il est temps de botter le cul et mâcher de la gomme à bulles!
</div>
Then, with Selenium, you can get the element, get the inner text and verify! Example in Java:
// assuming driver is a good WebDriver instance
WebElement elem = driver.findElement(By.xpath("//div"));
if (elem.getText().contains("kick ass")) {
System.out.println("It's English!");
} else if (elem.getText().contains("botter le cul")) {
System.out.println("It's French!");
}
As of Java 7, you can even use a switch-case on a String, so you can digestedly test against many, many languages.

Well, you can
search for flag of that language on the page
check number formatting, or time formatting (does change in some locales)
Verify some well known text (like greeting) is changed. Say, from Good evening to Dobrý večer (that was in Czech ;) )

We use dictionary files for l10n. Dictionary is an xml file with strings stored like <string key="Cancel">Cancel</string>.
So for testing purposes we replace all </string> with something like ###</string> and replace all spaces between <string key="..."> and </string> with '_' (can be done in notepad++ with ctrl+h, spaces can be replaced with the help of this answer for example). Then we select language that corresponds to modified dictionary at our website. Next step is done by Selenium IDE script: browsing through the whole web site and storing pages' text with the use of Selenium IDE command storeBodyText | text. Then parsing and echo all words that is not ended with ### and analyze if it ok or the word that should be translated is hard-coded. Not pure automation but better than nothing :) I think this approach can be applied not only for xml-dictionary files but for any storage you use for your strings.
PS. If you don't want to perform localization testing but just want to be sure that by clicking on link some language is applied (I'm afraid this is exactly what you are looking for), after you click at your link you can get text from any element and compare it with expected text (storeText(locator, variableName) for IDE).

<!-- Using Selenium IDE -->
<tr>
<td>storeAttribute</td>
<td>//html#lang</td>
<td>language</td>
</tr>
<tr>
<td>echo</td>
<td>The label is ${language}</td>
<td></td>
</tr>

Related

Selenium XPath find element where second text child element contains certain text (use contains on array item)

The page contains a multi-select dropdown (similar to the one below)
The html code looks like the below:
<div class="button-and-dropdown-div>
<button class="Multi-Select-Button">multi-select button</button>
<div class="dropdown-containing-options>
<label class="dropdown-item">
<input class="checkbox">
"
Name
"
</label>
<label class="dropdown-item">
<input class="checkbox">
"
Address
"
</label>
</div>
After testing in firefox developer tools, I was finally able to figure out the xPath needed in order to get the text for a certain label ...
The below XPath statement will return the the text "Phone"
$x("(//label[#class='dropdown-item'])[4]/text()[2]")
The label contains multiple text items (although it looks like there is just one text object when looking at the UI) in the label element. There are actually two text elements within each label element. The first is always empty, the second contains the actual text (as shown in the below image when observing the element through the Firefox developer tool's console window):
Question:
How do I modify the XPath shown above in order to use in Selenium's FindElement?
Driver.FindElement(By.XPath("?"));
I know how to use the contains tool, but apparently not with more complex XPath statements. I was pretty sure one of the below would work but they did not (develop tool complain of a syntax error):
$x("(//label[#class='dropdown-item' and text()[2][contains(., 'Name')]]")
$x("(//label[#class='dropdown-item' and contains(text()[2], 'Name')]")
I am using the 'contains' in order to avoid white-space conflicts.
Additional for learning purposes (good for XPath debugging):
just in case anyone comes across this who is new to XPath, I wanted to show what the data structure of these label objects looked like. You can explore the data structure of objects within your webpage by using the Firefox Console window within the developer tools (F12). As you can see, the label element contains three sub-items; text which is empty, then the inpput checkbox, then some more text which has the actual text in it (not ideal). In the picture below, you can see the part of the webpage that corresponds to the label data structure.
If you are looking to find the element that contains "Name" given the HTML above, you can use
//label[#class='dropdown-item'][contains(.,'Name')]
So finally got it to work. The Firefox developer environment was correct when it stated there was a syntax problem with the XPath strings.
The following XPath string finally returned the desired result:
$x("//label[#class='dropdown-item' and contains(text()[2], 'Name')]")

How to use special characters on pentaho Dashboard

I'm trying to use special characters on my dashboard using a HTML structure.
It only works if I use HTML Entities such as "& atilde;" (without space) for ã.
But is it the only way to do it? Is there anywhere I can set UTF-8, for example?
I tried to put a META tag setting UTF-8, but I didn't work.
Here's what I'm doying:
Input:
Output:
I need to type: "Alocação de Funcionários"
Notice that I also set a custom noDataMessage_text on Advanced Properties > Extension points of my first Bar Char and, since the message also have special characters on it, using the HTML Entity would certainly not be a good idea.
UPDATE:
I have the same problem when I was looking for my Cubes when I was using the OLAP Selector Wizard
I think your problem will solve. You can use like these.
<h1 style="font-weight: bold;"> Alocação de Funcionários<h1>
or
<h1 style="color:#297385l"> AlocaÇão de Funcionários</h1>
I got these output in my dashboard.
I am thinking your font family is creating some issue. Please copy the exact h1 tag line and paste it in your dashboard let's see.
Thank you.

Handle elements that have changing ids all the time through Selenium Webdriver

I am running the script to automate test cases and having this unique problem.
I have detected and used IDs of the elements for click etc. purpose. However, all of a sudden these ids have changed and the script works no more.
Another weird thing is those IDs are same as in script when inspected in Chrome but different in Firefox driver browser.
Firebug for test driver: -
<p class="description" onclick="selectElementTextListForIE(this,'tile29', 'tile19');selectElementTextList(this,'tile29', '')" id="tile29_span_0_0">
Platinum
</p>
Chrome inspector for same element: -
<p class="description" onclick="selectElementTextListForIE(this,'tile20', 'tile19');selectElementTextList(this,'tile20', '')" id="tile20_span_0_0">
Platinum
</p>
Also, what could be the best strategy for detecting such elements whose IDs are generated on run.
I even tried using XPATH but that too contains id's reference
eg. #id="tile276_input
Any help will be appreciated.
Thanks.
Abhishek
You can utilize CSS for this. For your element, looks like its:
<* id="tile276_input" />
What you need to do is find out what is changing about it. I assume it's the number inbetween. If it is, then your selector would look something like:
By.cssSelector("*[id^='tile'][id$='input']")
This will look for anything that has an ID that "starts with tile" and "ends with input. In our case, "tile276_input" matches that.
See this article if you want more information
You also can try contains and starts-with() for such things
driver.findElement(By.xpath("//*[contains(#id,'title')]"))
or
driver.findElement(By.xpath("//* [start-with(#id,'title')]"))
WebElement element = driver.getElement(By.cssSelector("[id^='title']);
Or
WebElement element = driver.getElement(By.cssSelector("id:contains('title')"));
You Can use this element to do desired actions.

How to set the default value of input item with jQuery EasyUI framework

I am trying to set the default value of an input item from last two days.
For this, i have also searched in google but till not cannot find the solution.
I am using jQuery EasyUI framework.
<div class="fitem">
<tr>
<td></td>
<td>
<input type="text" class="easyui-validatebox" name="insertby" id="insertby" size="20">
</td>
</tr>
</div>
<script>
var s = '<?php echo $logname; ?>';
document.getElementById('insertby').value = s ;
alert(s);
</script>
As I am unable to add a comment to ask you to try stuff, I will try my best to help you out!
Firstly, your code works for me. However, there are times where other javascript codes causes errors and stops the code execution before your block of code. You might want to try pressing F12 on your Chrome browser to see if you encounter any errors before your block of code to ensure that all is well.
this code snip might have you
http://www.jeasyui.com/forum/index.php?topic=2623.0
$('#insertby').validatebox('setValue', s);
I took me while to "get it" too.
Actually, jquery easyUI modifies the DOM on the fly to make its fancy things in a way that the original input box is "gone" while you obtain their fancy widget instead. That's why modifying the input field directly has no effect, it is hidden actually. I guess this is done so because their getters/setters should be used in order to update everything correctly.
EasyUI is very easy to set up and play with, but it's way to operate on elements is rather unintuitive. But once you got the hang of it, it should be all right.
Use
setValue. $('idofcombogrid').('setValue',id_value);
The id_value refers to the value of idField as defined initially for the combogrid.

How to check if a text is in web page in Robot Framework and Selenium

I'm currently creating an automation test for a website and I want to check if a text(s) is in the page. I could use the keyword 'Page should contain' to check; however, I want it to be a little more specific on having it check specifically where the text exist in the page. Is there a way I can have it check if a specific div contains the text?
You can easily do this with a built-in Selenium2Library tags.
For a partial match use this:
Element Should Contain locator expected_text
For an exact match use this:
Element Text Should Be locator expected_text
If your HTML code is something like:
Your div tag and need to find FindMe
<div class="gwt-Label">This FindMe DIV</div>
Then you can find "FindMe" text like:
//div[#class='gwt-Label'][contains(string(),'FindMe')]