How can I check and save text from span element - gatling

I have been trying to get the text out of a span element without much success.
using the following:
.check(css("span[id='hostName']", "text").saveAs("__HOST")))
but it does not find the text.
this is the html
<span id="hostName" style="padding:0">01</span>
can i do this with css checker or do i have to resort to regex

Direct quote from the Gatling documentation:
css(expression, attribute)
expression can be a plain String, a String using Gatling EL or an Expression[String].
attribute is an optional String.
When filled, check is performed against the attribute value. Otherwise check is performed against the node text content.

Related

How to achieve string contains operator with react-awesome-query-builder for type text

I'm using react-awesome-query-builder in my project. My requirement is having a field of type text and checking if this field is equals (achieved by using equal operator)/does not equal (achieved by using not_equal) a particular input string. SO far so good. I also want to check if the field contains some string? Looking for some help on how to check for java type string#contains functionality with this library.

need xpath where the next descendant that has text is returned

I am trying to write a locator where the next text descendant is returned. I wont know the text. The following xpath works:
//*[#id='myChart']//label[contains(text(),"Show:")]/following::div[4]
but I dont like the div[4] as this could easily change. The element is the first div type descendant under show that contains text. Any suggestions?
A
Considering the following clauses:
the next text descendant
I wont know the text
div[4] as this could easily change
element is the first div type descendant
To locate the element a couple of effective approaches are as follows:
Using xpath:
//*[#id='myChart']//label[contains(., "Show")]//div[text()]
Using xpath with descendant:
//*[#id='myChart']//label[contains(., "Show")]//descendant::div[text()]
Using xpath with following:
//*[#id='myChart']//label[contains(., "Show")]//following::div[text()]
I think this will work for you:
//*[#id='myChart']//label[contains(text(),"Show:")]//div[text()]
To give more confident answer we need to see the actual page / XML.
In case the desired div is a direct child of the label containing the "Show:" the above expression can be presided to
//*[#id='myChart']//label[contains(text(),"Show:")]/div[text()]

How to Print the Disabled text from Geb/Groovy?

enter image description here
We are automating the UI Application, Our UI application have Disabled Text are present, so we need to Validate the Disabled text. Before validating, I have to Print the Disabled text, Please guide me to how to print the text using Geb/Groovy.
Please find the Image of HTML tag which i highlighted is the Disabled text
BNSF0000712570
BNSF0000712570
The selector above will yield multiple results, i.e. elements, if there is more than one element that matches the classes used in the By.cssSelector query.
To get only the element containing "BNSF0000712570", I would suggest you try to get it using the "ext:qtip" attribute instead (which I assume is unique per element containing a disabled text) on the div containing the disabled text:
def myText = $(“div[ext:qtip=‘Id: 0001’]”).text();
println myText;
assert myText == "BNSF0000712570";
#Saurabh Gar: Why would you use the WebDriver "By" class selectors? With Geb you have access to a wide range of simpler ways to write selectors, e.g. like the one used above.
You should try using By.cssSelector as below :-
def text = driver.findElement(By.cssSelector("td.x-grid3-td-elementvalue").text
Or
def text = driver.findElement(By.cssSelector("div.x-grid3-col-elementvalue").text
assert text == "BNSF0000712570"
println text
Note:- If still doesn't get the text need to share table HTML insteadof screenshot that's why, could make a best locator.
Hope it helps..:)

How to convert <node/> to <node></node> with libxml (converting empty elements to start-end tag pairs)

While generating an XML content, I get an empty node <node/>, and I want it to be <node></node>. (Since <node></node> is the correct form of c14n, the progress called "converting empty elements to start-end tag pairs")
How should I convert it?
There's a way hinted by Jim Garrison(Thank you) to do this,
by using xmlBufferCreate, xmlSaveToBuffer, xmlSaveDoc, xmlSaveClose
with xmlSaveOption: XML_SAVE_NO_EMPTY
Take a look at the libxml2 documentation, specifically xmlSaveOption value XML_SAVE_NO_EMPTY
I found another way which is easier when the nodes are generated under control, by simply giving value "" to the node.

unterminated string literal error in salesforce

I am trying to get a value from salesforce class into a javascript variable. I am able to get the value if its a single line value, but if its multiline textarea it gives a unterminated string literal error
caseUpdate.Description = "{!ac__c.C_Info__c}";
After googling for sometime i came to know we can have a workaround for this by having a hidden field and using DOM storing it using the document.getElement.Id. But i am calling this code on a button click so i would not be able to create a input text or hidden field value.
Any body who can provide an way to do it?
Thanks
Prady
You should just be able to use the standard Salesforce JSENCODE() function if you are using OnClick Javascript in a button. This will escape any characters for you.
See the documentation.
It is because of line breaks. merge fields are rendered unescaped into the output stream meaning that CRLFs push into a new line and break javascript strings. Either use the div/input trick or use Apex to replace \r\n's in the field with <br/> or whatever best suits the purpose. Also keep in mind that " will also terminate your JS string.
The easiest way is to just include a function in your extension and then you can use it across board
public String FixNewLine(String s) {
if (s != null) return s.replaceAll('\r\n', '<br/>').replaceAll('"', '\\"');
return null;
}
I had the same issue but was able to fix it! The trick is the JSENCODE function. Its basically {!JSENCODE(Obj.Field)}"; So you are replacing your merge field with this function and nesting the merge field itself within the function. In my scenario I ended up with opptyObj.Description="{!JSENCODE(Case.Description)}"; as my total syntax. First calling upon my set object and field, and then the merge data to populate it.

Resources