JMeter: how to find color attribute of H1? - jmeter

I am trying to find if the same color is applied on all H1s (heading) on a list of pages.
I am trying the below way of doing it, but it is resulting balnk not even "colorNotFound"
What am I doing wrong?

I don't think <h1> elements can have "color" attribute, as far as I recall <font> has
Whatever
The situation you're trying to describe may occur when there is a match but i.e. the element doesn't have the color attribute like here:
So your getH1 variable will have blank value
And if there is a match and the attribute is there - your variable will have this attribute value:
Unfortunately we're not telepathic enough in order to help you to fix your CSS selector query without seeing at least partial HTML response you're trying to validate so in the meantime I can only suggest getting familiarized with How to Use the CSS/JQuery Extractor in JMeter guide

Related

xpath find a CSS attribute from DOM not inline

See my code here of my scenarioI have this scenario and I need to use xpath to validate the image, and the gradient colors are present. I tried all kind of xpath combination but still getting errors or not finding it. Many other samples have the style in-line. In this case has a "." class outside of a close tag. code in the image
Could some offer a hand?your text

Setting the correct xpath

I'm trying to set the right xpath for using RSelenium, but I'm not very experienced in this area, so any help would be much appreciated.
Since I'm not allowed to post pictures yet I have tried to add a link to a screenshot of the html:
The html
I need R to scrape the dates (28-10-2020 - 13-11-2020), but so far I have not been able to set the correct xpath when using html.nodes.
I'm trying to scrape from sites like this one: https://www.boligsiden.dk/adresse/topperne-9-3-33-2620-albertslund-01650532___9__3__33
I usually do this on python rather than R
As you can see in this image when you right-click on the element concerned. You get a drop-down menu with an x-path to the element.
Other than that, the site orientation and x-path might change and a full x-path might be a good option in the short-run, so I rather prefer driver.find_element_by_xpath('//button[contains(text(),"Login")]')\ .click()
In your case which would be find_element_by_xpath('//*[contains(#class, 'u-pb-4 u-block')]')
I hope this helps and it is mostly the same across different languages

How to assert multiple elements values in a form using Xpath Assertion in Jmeter?

I'm trying to assert some text-fields values in a form
and I can only assert on a single one through Xpath Assertion post-processor.
How can I assert the whole form fields within a single http sampler ?
I tried to assert multiple text-fields in a single "Xpath Assertion" component, but it didn't work.
Here a couple of fields I'm trying to assert in a single Xpath Assertion component:
//*[#class='ProjectNameInput']/#value='Dummy_Project'
//*[#class='Desc2']/#value='Dummy_Desc'[enter image description here][1]
I would take a simple approach using xpath. As you are expecting all the fields in a form you can write the xpath to get the form element if it have all the required value elements.
For example in the SO question when you click on Add Comment (right below your question). That comment text area,Add Comment button and help button are part of the form. I want to verify if all those elements are present with the given text. Then I can use below xpath.
So in your case you can do something like this.
//form[.//xpath_of_first_element and .//xpath_of_2nd_element and .//xpath_of_3rd_element]
Make sure you specify the .// in the [] otherwise it will check the entire page rather under the form.
Going forward consider adding at least partial or better full page DOM to your question, the chance of getting a comprehensive answer will be much higher.
In the meantime, given you have following HTML form
<form>
<input type="text" class="ProjectNameInput" value="Dummy_Project"/>
<input type="text" class="Desc2" value="Dummy_Desc"/>
</form>
you can use the following XPath expression in order to match 2 nested <input> tags:
//form[./input[#class='ProjectNameInput']/#value='Dummy_Project' and ./input[#class='Desc2']/#value='Dummy_Desc']
Demo:
More information: Using the XPath Extractor in JMeter

How can I query XPath matching an attribute from one tag against another attribute from another tag?

I'm scripting a web app that has labels for input fields. EG:
<label for="surname">Family Name:</label>...<input id="surname" ...></input>
I'd like to be able to write an XPath expression that takes the text "Family Name:" to match the label, then takes the "for" attribute from the label and uses that to find the associated input tag by matching its "id" tag.
I can make this "work" as follows:
//label[contains(.,"Family Name:")]/following::input[1]
However, for this web app I think it would be more reliable to match for/id. (EG: How can I be sure that in all possible layouts the first input tag following the label is the one I want? And what happens if somewhere down the line this page is rendered using a right-to-left script?
My ultimate aim is to create a library function that we can use to write QA scripts in advance of web pages to test against, when all we have is a picture or document with an input field labelled "Family Name:" and no idea what id some programmer will ultimately assign to the field.
Maybe this is what you're looking for?
//input[#id = //label[contains(., "Family Name:")]/#for]
As for your ultimate goal, you may want to take a look at the XPath gem for Ruby. Some of what you're doing may already be implemented there. (Specifically, check out the library's HTML Helpers)

extract xpath

I want to retrieve the xpath of an attribute (example "brand" of a product from a retailer website).
One way of doing it is using addons like xpather or xpath checker to firefox, opening up the website using firefox and right clicking the desired attrbute I am interested in. This is ok. But I want to capture this information for many attributes and right clicking each and every attribute maybe time consuming. Also, the other problem I have is that attributes I maybe interested in will be there for one product. The other attributes maybe for some other product. So, I will have to go that product & then do it manually again.
Is there an automated or programatic way of retrieving the xpath of the desired attributes from a website rather than having to do this manually?
You must notice that not all websites use valid XML that you can use xpath on...
That said, you should check out some HTML parsers that will allow you to use xpath on HTML even if it is not a valid XML.
Since you did not specify the technology you are working with - I'll suggest the .NET HTML Agility Pack, if you need others, search for questions dealing with this here on SO.
The solution I use for this kind of thing is to write an xpath something like this:
//*[text()="Brand"]/following-sibling::*
//*[text()="Color"]/following-sibling::*
//*[text()="Size"]/following-sibling::*
//*[text()="Material"]/following-sibling::*
It works by finding all elements (labels) with the text you want and then looking to the next sibling in the HTML. Without a specific URL to see I can't help any further.
This is a generalised version you can make more specific versions by replacing the asterisks is tag types, and you can navigate differently by replacing the axis following sibling with something else.
I use xPaths in import.io to make APIs for this kind of thing all the time, It's just a matter of finding a xPath that's generic enough to find the HTML no matter where it is on the page, but being specific enough to get the right data.

Resources