How to use Assert/Verify in gotoif - selenium

I have been looking around but cant seem to find a solution.
I want to do the following:
Assert/Verify an element is present
If the element is present go to label.
i have tried:
<tr>
<td>verifyElementPresent</td>
<td>css=#error_div > div.content</td>
<td>errorPresent</td>
</tr>
<tr>
<td>gotoIf</td>
<td>"${errorPresent}" == "true"</td>
<td>FAIL</td>
</tr>
.. BLa bla some other steps
<tr>
<td>label</td>
<td>FAIL</td>
<td></td>
</tr>
I have tried changing if to assert element but no luck.
Any suggestions?

This should work:
<tr>
<td>storeElementPresent</td>
<td>css=#error_div > div.content</td>
<td>isPresent</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars.isPresent</td>
<td>FAIL</td>
</tr>
.. BLa bla some other steps
<tr>
<td>label</td>
<td>FAIL</td>
<td></td>
</tr>

I struggled with this for a little while. this is the code that worked for me Anything in bold you can replace with your item of choice
<tr>
<td>storeElementPresent</td>
<td>WHAT YOU ARE LOOKING FOR</td>
<td>isPresent</td>
</tr>
<tr>
<td>gotoIf</td>
<td>${isPresent} == false</td>
<td>FAIL</td>
</tr>
THE CODE YOU WISH TO EXICUTE IF IT FINDS WHAT YOU ARE LOOKING FOR
<tr>
<td>label</td>
<td>FAIL</td>
<td></td>
</tr>
You can replace false with true if you wish to look for something is there. You can also change the label from FAIL to any other text.
In the event you have more than one gotoIf statement then you will have to change your label for each statement (eg. FAIL, FAIL1, FAIL2, etc)
Credit to Yeven Ulyanenkov over in this thread
In order to run gotoIf statements you need to download sideflow by Darren DeRidder
Github - sideflow

Related

XPATH to use preceding and following sibling in a single statement

I would like to scrape name, address informations between tag contains defendent text and another tag,
My HTML structure is:
<hr>
<H5>Defendant/Respondent Information</H5>
<span class="InfoChargeStatement">(Each Defendant/Respondent is displayed below)</span>
<table>
<tr>
<td><span class="FirstColumnPrompt">Party Type:</span></td><td><span class="Value">Defendant</span><span class="Prompt">Party No.:</span><span class="Value">1</span></td>
</tr>
</table>
<table>
<tr>
<td><span class="FirstColumnPrompt">Name:</span></td><td><span class="Value">Name 1</span></td>
</tr>
</table>
<table>
<tr>
<td><span class="FirstColumnPrompt">Address:</span></td><td><span class="Value">Addr 1</span></td>
</tr>
<tr>
<td><span class="FirstColumnPrompt">City:</span></td><td><span class="Value">city1</span><span class="Prompt">State:</span><span class="Value">aa</span><span class="Prompt">Zip Code:</span><span class="Value">Zip1</span></td>
</tr>
</table>
<hr>
<table>
<tr>
<td><span class="FirstColumnPrompt">Party Type:</span></td><td><span class="Value">Defendant</span><span class="Prompt">Party No.:</span><span class="Value">2</span></td>
</tr>
</table>
<table>
<tr>
<td><span class="FirstColumnPrompt">Name:</span></td><td><span class="Value">Name 2</span></td>
</tr>
</table>
<table>
<tr>
<td><span class="FirstColumnPrompt">Address:</span></td><td><span class="Value">Addr2</span></td>
</tr>
<tr>
<td><span class="FirstColumnPrompt">City:</span></td><td><span class="Value">City2</span><span class="Prompt">State:</span><span class="Value">st2</span><span class="Prompt">Zip Code:</span><span class="Value">zip2</span></td>
</tr>
</table>
<hr>
<H5>Related Persons Information</H5>
<span class="InfoChargeStatement">(Each Related person is displayed below)</span>
<table>
<tr>
<td><span class="FirstColumnPrompt">Name:</span></td><td><span class="Value">Unwanted Name</span></td>
</tr>
</table>
<table>
<tr>
<td><span class="FirstColumnPrompt">Address:</span></td><td><span class="Value">un addr</span></td>
</tr>
<tr>
<td><span class="FirstColumnPrompt">City:</span></td><td><span class="Value">Unwanted City</span><span class="Prompt">State:</span><span class="Value">Unwanted city</span><span class="Prompt">Zip Code:</span><span class="Value">12345</span></td>
</tr>
</table>
<table></table>
<hr>
My current XPATH capturing the first occurence of Name and address properly, but if need to extract the multiple occurences, it also scrape the information from the unwanted h5 tags.
My current XPATH is,
"//*[contains(text(),'Defendant')]//following-sibling::table//span[text()='Name:' or text()='Business or Organization Name:']/ancestor-or-self::td/following-sibling::td//text()")
I tried including preceding sibling and following sibling but nothing gives my expected output,
My current output is..
names - [
Name1,
Name2
Unwanted Name,
]
Expected output is,
[
Name1
Name2
]
Kindly help.
try this:
"//H5[contains(text(),'Defendant')]/following-sibling::table[not(preceding-sibling::H5[not(contains(text(),'Defendant'))])]/tr[td[1][span[text()[.='Name:' ]]]]/td[2]/span/text()"
It first selects the table that has not a preceding-sibling::h5 with text() that not contains 'Defendant' and than
selects from the correct table the tr where the first td meets your requirements and selects the second td
No need for double slashes which is bad for performance
EDIT 1
Since there are more preceding-sibling::h5 than the example shows, this XPath will deal with that:
"//H5[contains(text(),'Defendant')]/following-sibling::table[preceding-sibling::H5[1][contains(text(),'Defendant')]]//tr[td[1][span[text()[.='Name:' ]]]]/td[2]/span/text()"
This will only select those tables that have as there first preceding-sibling::h5 the same h5 as we were interested in
EDIT 2
Actually now the first h5 select is redundant. This XPath will do:
"//table[preceding-sibling::H5[1][contains(text(),'Defendant')]]//tr[td[1][span[text()[.='Name:' ]]]]/td[2]/span/text()"

How to make subtitles in Quasar table

I working on Vue3 with Quasar/cli.
How to make this category dividers (blue subtitles) with Quasar component qTable or qMarkupTable? screen
Ive tried to figure out body slots but I couldnt
Link to qTable API doc
https://quasar.dev/vue-components/table#introduction
Link to qMarkupTable API doc
https://quasar.dev/vue-components/markup-table#introduction
For QMarkupTable, add a row whose TD spans all the columns:
<q-markup-table>
<thead>
<tr>
<th>№</th>
<th>Name</th>
<th>Code</th>
<th>Diff</th>
</tr>
</thead>
<tbody>
<tr class="bg-primary text-white">
<td colspan="4">Medicines</td>
</tr>
<tr>
<td>1</td>
<td>Mukosolvan</td>
<td>101492</td>
<td class="text-negative">1</td>
</tr>
</tbody>
</q-markup-table>
QMarkupTable is a regular HTML table - it just applies the proper styling on it, everything else is the same HTML you've been studying as a student.

Can I verify if a dynamic text is in a stored variable with Selenium IDE?

I am testing a system and I encountered following issue: I must assert that certain elements are on the page only if an admin is logged in. To do so I must first verify the logged in user is on the list of admins. This is what I have done so far:
<tr> //storing the username in a variable
<td>storeText</td>
<td>css=#myAccount > span</td>
<td>user</td>
</tr>
<tr>
<td>echo</td>
<td>${user}</td>
<td></td>
</tr>
<tr> //this is where all the admins ID´s are stored
<td>storeValue</td>
<td>css=#new_user</td>
<td>allAdmins</td>
</tr>
<tr>
<td>echo</td>
<td>${allAdmins}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>javascript{storedVars['allAdmins'].search(storedVars['allAdmins']);}</td>
<td>validate</td>
</tr>
<tr>
<td>echo</td>
<td>${validate}</td>
<td></td>
</tr>
The result that I get is always 0 as in false. I tried to write instead of .search(storedVars['allAdmins']);} search("srv_admin");} since is one of the admins users in the list but I still get a false. Is is even possible to do that with selenium IDE?

selenium xpath, how to select last matching element in a table?

Given
<table>
<tr>
<td>service1</td>
</tr>
<tr>
<td>service2</td>
</tr>
<tr>
<td>service3</td>
</tr>
<tr>
<td>blip</td>
</tr>
</table>
How can I select the last 'service-n' row when I don't know what n will be?
I have tried adding [last()] but it didn't work.
I have:
//table//tr//td[contains(text(),'service')]
but it selects the 1st row and I want the last one.
I can't use tr[3] because in reality the number of 'service-n' rows is dynamic and changes a lot.
The answer was exactly where I put the [last()] and I had it in the wrong place
It goes here:
//div[#id='content']//table//tr[last()]//td[contains(text(),'service')][last()]/following-sibling::td[2]
Not here:
//div[#id='content']//table//tr[last()]//td[contains(text(),'service')]/following-sibling::td[2][last()]
try with cssSelector, this way.
By.cssSelector("table tr:last-child td")
List<WebElement> allElement=fd.findElements(By.xpath("//table//td[contains(.,'service')]");
int count=allElement.size();
allElement.get(count-1).click();
<table id="table1">
<tbody>
<tr id="tr1">
<td id="td1"></td>
<td id="td2"></td>
<tr>
<tr id="tr2">
<td id="td3"></td>
<td id="td4"></td>
<tr>
<tbody>
</table>
Then to target last td of last tr
we can have xpath as:xpath="//table[#id='table1']//tr[last()]//td[last()]";
(//div[#id='name'])[last()]
By using we can get the last element of the relevant filed.
//div[#id='name'][last()]
Multiple elements in last

Selenium IDE - Click command keeps loading and wont go to the next step

I want to click this button:
html:
onclick="javascript:return scForm.postEvent(this,event,'contentlink:externallink(id=FIELD8547822616)')" class="scContentButton" href="#">Insert External Link
After clicking the button, a new window will be opened.
I've tried several command such as click, fire event - click. Both of them will open the new window but it won't go to the next step. The "click" row will be highlighted yellow (means that it's still in progress).
Why is it after click, the next step isn't executed ?
My Code:
Hi here's my code in selenium ide
<tr>
<td>click</td>
<td>//div[#id='EditorPanel']/div[3]/div/table[5]/tbody/tr/td/table[4]/tbody/tr/td[2]/div/a[3]</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>Sitecore</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=Url</td>
<td>http://bookofbetterways.com</td>
</tr>
<tr>
<td>click</td>
<td>id=OK</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td></td>
<td></td>
</tr>
Add to your code the following command before the command selectWindow, so the script will wait, the window to be loaded before select it.
<tr>
<td>waitForPopUp</td>
<td></td>
<td></td>
</tr>
Based on assumption that your next step is to be executed on the opened window there may be a case that after clicking when the new window is opened you are not selecting the opened window.