css message locator in robotframework - css

Please advice me about to find css message locator in robotframework.
I can not use id cause of change every time when I run test script.
Only Class not change but have a lot of message.
Hence I want to catch the message instead.
enter image description here
enter image description here

As far as I could understand, you need to select an element based on CSS class. If you need exactly that solution, you can go with CSS locator css:z-menu-img, if you are sure that this is the only element with that CSS class in the page.
Otherwise, I propose another solution (as unstable as the others because it can change over time): use XPath. For your case, it can be: //*[#id="kOIQf6-a"]/span.

Related

Semantically searching in CSS files

Imagine I have a huge CSS file with e.g. more than 40000 lines, like https://cdn.jsdelivr.net/npm/semantic-ui#2.4.2/dist/semantic.css
I want to explore this file and for example search for class definitions containing "hidden" in their name. How can this be done? The word "hidden" can also appear in the definition of the class, so a normal text search is not sufficient. So I am looking for a tool which is able to interpret the CSS file and then allows me to semantically search in it, understanding the difference between "hidden" in a class name and "hidden" in a class definition.
Any tips on this? Thanks!
Update: I am using Visual Studio Code, if there is a matching extension for it, that would be great. A separate tool would also be fine.
I’m not sure which text editor/IDE you are using but most IDE’s allow you to search for classes by name, in which case you could just use “hidden” as the input. In IntelliJ, the command for this is Ctrl+N. You’ll have to check your editor or IDE for the shortcut but a simple Google search should give you the answer.

How to click on a link based on text in a table using selenium

Hi All,
I have the following table with links that I need to select. In this specific example I need to select the DIY Payroll but sometimes this can change its position within the table. The current xpath is:
.//*[#id='catalog-category-div-1']/table/tbody/tr/td1/ul/li[4]/a
So I do a:
By.xpath(".//*[#id='catalog-category-div-1']/table/tbody/tr/td[1]/ul/li[4]/a").click()
But the problem is here is that it can change position where it can be in td[2] or td[3] and li[n'th postion]
Can I have selenium go through the table and click on it based on text. Will the By.linktext() work here ?
You can use the following codes these codes will handle the dynamic changes.
You can use linkText() method as follows:
driver.findElement(By.linkText("DIY Payroll")).click();
If you want to use xpath then you can use following code.
driver.findElement(By.xpath(.//a[contains(text(),'DIY Payroll')).click();
If you need any more clarification you are welcome :)
I would suggest that you try By.linkText() or By.partialLinkText(). It will locate an A tag that contains the desired text.
driver.findElement(By.linkText("DIY Payroll")).click();
A couple issues you might run into:
The link text may exist more than once on the page. In this case, find an element that's easy to find (e.g. by id) that is a parent of only the link you want and then search from that element.
driver.findElement(By.id("someId")).findElement(By.linkText("DIY Payroll")).click();
The A tag may contain extra spaces, other characters, be capitalized, etc. In these case, you'll just have to try using .partialLinkText() or trial and error.
In some cases I've seen a link that isn't an A tag or contains additional tags inside. In this case, you're going to have to find another method to locate the text like XPath.
You should use a CSS selector for this case:
Can you try:
By.CssSelector("a.browse-catalog-categories-link")
You can use XPath to do this. //a will select all 'a' tags. The part inside of the square brackets will select everything with text "DIY Payroll". Combined together you get the desired solution.
//a[contains(text(),'DIY Payroll')]

Load resources in gadgets in Jira

I've made an Add-on which is a custom field.
The style of the text in the field changes depending on the properties of an issue.
I check which style should the text have in the .java file and I pass the html class in a variable called $indicator to the velocity template:
#if( ${value} )
<span class="$indicator">${value}</span>
#end
It works perfect everywhere but in gadgets. When I add this field to a table showing issues in a dashboard, the html code is correct, but it doesn't find the css resource. This is because gadgets are inside an iframe.
How can I make the iframe have a reference to the stylesheet?
You did not say exactly which gadget you were using, but try adding the following context within your <web-resource> module:
<context>jira.webresources:issue-table</context>
The above should work for at least Assigned to Me, Filter Results, In Progress, Voted, and Watched in JIRA 6.1+.
If that does not work, you might also try:
<context>com.atlassian.jira.gadgets:common-lite</context>
If that general context doesn't work, you can look for which exact contexts are #requireContext'ed by the specific gadget you are trying to use, and then make sure that your web-resource is listed in that context. You can figure this out by looking at the gadget's XML and then searching for the #requireContext. (You can find the gadget XMLs inside $JIRA_DATA/plugins/.osgi-plugins/transformed-plugins/jira-gadgets-plugin-*.jar)
Starting with JIRA 7 the Answer of Scott Dudley is no longer working. #requireContext was replaced with a #requireResource within the Atlassian sources of this gadget.
As it affects our plugin, I created a Improvement Request to make that possible again

jwebunit to check css style

I'm trying to assert the current styling of a div. For example, is it set to visible or not. I wasn't able to find a way in jwebunit to get at this information though. Ideas? Alternate approaches?
Constraint: I cannot change the page I am trying to test.
There are two TestEngines which you can use with JWebUnit, HTMLUnit and Selenium. why not System.out.println("========="+ getPageSource()); and see if the page source return from both TestEngines gives css within the output. If they do that means you can verify css, if the output does not give css then i guess you will not be able to verify. One thing i know for sure is that it will show you the css file the page uses for style but as to the styling being applied I will say not, but try it

Selenium: css query regarding get_attribute() function

I am trying to find the attribute value of the title attribute.
Now, I have a list of similar links on the same page and I want to select the first link and get its title attribute.
I have used the following selenium command:
self.se.get_attribute("css=a[href*='radio?rid=']:nth-of-type(1)#title")
But it is giving me an error.
Could someone please help me figure out the problem?
Thanks
You should use XPath syntax instead of CSS selectors. You didn't post any HTML to match, so therefore a made up example: to get the title of the first link found in a div with id myDiv, use the following:
self.se.get_attribute("xpath=//div[#id='myDiv']//a[1]#title")
Where:
//div[#id='myDiv'] matches any div with id "myDiv";
//a[1] select the first link found anywhere in the previously selected div (use 2 for the second, and so on.
#title specifies the attribute you want to retrieve.

Resources