Robot Framework: How to parse blank text entries in a returned text list from a FOR Loop - automation

I have a functioning Robot Framework test that scrapes the elements of a page and returns the link text. My problem is, some of these fields are empty and some of them have text. I do not care what the text is, however. This is an example of the output I get:
"Link Text="
"Link Text=" John Doe
"Link Text=" Jane Doe
In this case, I would only want the program to return items 2 and 3, and not Log item 1. Here is my code to achieve this right now.
TEST
${Count}= Get Element Count //a
Log To Console Total= ${Count} \n
FOR ${INDEX} IN RANGE 1 ${Count}-1
${text}= Get Text xpath=(//a)[${INDEX}]
${href}= Run Keyword And Return Status Get Element Attribute xpath=(//a)[${INDEX}] #href
Run Keyword If ${href} Log To Console ${INDEX}. "Link Text=" ${text}
... ELSE Log To Console NONE
END
So this does give me a pass, and I do get the link text I'm asking for. I just need to take out the blank entries. I know my loop is functional, but I can't figure out how to parse the blank fields. How can I do this? Any ideas? Please let me know, thanks so much!

In these situations I usualy use Get Length and test if greater than zero.
Here is your modified example:
TEST
${Count}= Get Element Count //a
Log To Console Total= ${Count} \n
FOR ${INDEX} IN RANGE 1 ${Count}-1
${text}= Get Text xpath=(//a)[${INDEX}]
${size}= Get Length ${text}
${href}= Run Keyword And Return Status Get Element Attribute xpath=(//a)[${INDEX}] #href
Run Keyword If ${href} and ${size} > 0 Log To Console ${INDEX}. "Link Text=" ${text}
... ELSE Log To Console NONE
END

Related

Selenium IDE doesn't match text, despite using correct wildcard

I'm using Selenium IDE in Chrome to test a web site. When the test runs successfully, the site produces the text " Success Saving Scenario!" Selenium IDE finds this text, but I can't find the right value to match that text.
Here's my setting:
Command: Assert Text
Target: css-li > span
Value: Success Saving Scenario
Each time I run this test, the IDE records a failure with the message:
assertText on css=li > span with value Success Saving Scenario Failed:
12:23:02
Actual value "Thu, 03 Feb 2022 17:23:02 GMT - Success Saving Scenario!" did not match "Success Saving Scenario"
I checked the page, and sure enough the text displays Thu, 03 Feb 2022 17:23:02 GMT - Success Saving Scenario!
Why does that not match Success Saving Scenario? I thought the asterisks would be a wildcard that would match any characters.
I've tried these values as well with no success:
glob: Success Saving Scenario
regexp: Success Saving Scenario
(just an asterisk by itself)
Any ideas?
I would use 'Assert Element Present' for this case. Find another locator from the dropdown with a 'contain' keyword and remove the timezone from the contain keyword as needed. Leave value field empty.
Sample
Command: assert element present | Target: xpath=//span[contains(.,'Success Saving Scenario')] | Value: empty

Clear empty value from List - Robot framework

I am a list which is - ['','','','Some-Value','',''] , I am trying to remove all the null/empty values from list so that the final result be ['Some-Value'].
Below is the code which I tried but so no luck so far
${list_size} = Get Length ${list}
For ${index} IN RANGE ${list_size}
${item} Get Form List ${list} ${index}
Run Keyword if '${item}' == '' Remove ${item} from list ${list}
enter code here
End
Can anyone help to solve this problem ? Thank you!
Robot framework enables you to use Evaluate keyword, and than it is just a python problem.
This code example produces the result you are looking for.
*** Variables ***
#{list_variable} ${empty} some text ${empty}
*** Test Cases ***
Replace a String
${cleared_list}= Evaluate [x for x in #{list_variable} if x]
Log ${cleared_list}

In Finding Broken links script ( using Selenium Robot Framework) -In Get Request URL's are going twice by appending

I am not sure what's wrong in the below Get Request, when i run the script in Get Request link appended.
Issue :
GET Request : url=http://127.0.0.1:5000//http://127.0.0.1:5000/index.html
Please see the below code and the Report screenshot.
I am stuck here! Really appreciate for the help.
${url3} http://127.0.0.1:5000/
${BROWSER} chrome
*** Test Cases ***
BrokenLinksTest-ForPracticeSelenium-2ndPage
Open Browser ${url3} ${BROWSER}
Maximize Browser Window
VerifyAllLinksOn2ndPage
Close Browser
*** Keywords ***
VerifyAllLinksOn2ndPage
Comment Count Number Of Links on the Page
${AllLinksCount}= get element count xpath://a
Comment Log links count
Log ${AllLinksCount}
Comment Create a list to store link texts
#{LinkItems} Create List
Comment Loop through all links and store links value that has length more than 1 character
: FOR ${INDEX} IN RANGE 1 ${AllLinksCount}-1
\ Log ${INDEX}
\ ${link_text}= Get Text xpath=(//a)[${INDEX}] #<-- for what ? -->
\ ${href}= Get Element Attribute xpath=(//a)[${INDEX}] href
\ Log ${link_text}
\ log to console ("The link text is "${link_text}" & href is "${href}" ${INDEX})
\ ${linklength} Get Length ${link_text} #<-- you are checking text not href ? -->
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${href}
Log Many ${LinkItems}
Remove Values From List ${LinkItems} javascript:void(0) #<-- don't forget checking content on list -->
${linkitems_length} Get Length ${LinkItems}
Log Many ${LinkItems}
#{errors_msg} Create List
Create Session secondpage http://127.0.0.1:5000/
:FOR ${INDEX} IN RANGE ${linkitems_length}
\ Log Many ${LinkItems[${INDEX}]}
\ ${ret} get request secondpage ${LinkItems[${INDEX}]}
\ log to console ${ret}
\ log ${ret}
\ ${code} Run Keyword And Return Status Should Be Equal As Strings ${ret.status_code} 200
#\ log to console "Gonna link" ${LinkItems[${INDEX}]}
# \ click link ${LinkItems[${INDEX}]}
#\ Capture Page Screenshot
#\ Click Link link=${LinkItems[${INDEX}]}
\ Run Keyword Unless ${code} Append To List ${errors_msg} error :${LinkItems[${INDEX}]} | ${ret.status_code}
${check} Run Keyword And Return Status Lists Should Be Equal ${errors_msg} ${EMPTY}
Run Keyword Unless ${check} Fail Link \ assertion Failed with msg:\n#{errors_msg}
Sleep 1
Ok, the "problem" is with these two lines:
Create Session secondpage http://127.0.0.1:5000/
and:
${ret} get request secondpage ${LinkItems[${INDEX}]}
As your screens show, your list of items (#{LinkItems}) already contains full url links, e.g.: http://127.0.0.1:5000/index.html but the Create Session keyword adds another http://127.0.0.1:5000/ in front of each list item.
Think about it as BASE_URL set up by Create Session keyword and an endpoint, e.g. /index.html. Create Session and Get Request are used together, the former setting up BASE_URL, the latter the endpoint part of the URL. You can see the documentation for the Create Session keyword, it explains its second parameter:
url Base url of the server
To solve this, you'd need to store in #{LinkItems} only everything after last / (it seems so in your case), so for example only /index.html or /shop.html

To grep contents from a CSV/Text File using Autohotkey(AHK) Script

Can anyone please help me in writing a script in AHK based on below requirement.
Requirement:
I have a CSV/TXT file in my windows environment which contains 20,000+ records in below format.
So, when I run the script it should prompt a InputBox to enter an instance name.
Example : If i enter Instance4 , it should display result in MsgBox as ServerName4
Sample Format:
ServerName1,ServerIP,Instance1,Type
ServerName2,ServerIP,Instance2,Type
ServerName3,ServerIP,Instance3,Type
ServerName4,ServerIP,Instance4,Type
ServerName5,ServerIP,Instance5,Type
.
.
.
Also as the CSV/TXT file contains large no of records , pls also consider the best way to avoid delay in fetching the results.
Please post your code, or at least show what you've already done.
You can use a Parsing Loop with CSV as the delimiter, and make a variable for each 'Instance' who's value is that of the current row's 'ServerName'.
The steps are to first FileRead the data from the file, then Loop, Parse like so:
Loop, Parse, data, CSV
{
; Parses row by row, then column by column in each row.
; A_LoopField // Current value
; A_Index // Current loop's index
; Write a script that makes a variable named with the current value of column 3, and give it the value of column 1
}
After that, you can make a Goto loop that spams InputBox and following a command that prints out the needed variable using the MsgBox command, like so:
MsgBox % %input%

Selenium IDE - storeval- how to copy and paste

3 security questions appearing on the screen like in random order like 1,3,2 or 2.1 and then 3:
Pets name? 2. City you were born? 3. School you attend?
Lets say that answer is a last word of each question. How to code it in Selenium ide. I guess to use GoToif, GotoLabel and StoreEval? Also, the answer should be stripped to one last word without space and "?"
You can store text or value in Selenium IDE.
The Command : storeText | storeValue (or storeAttribute if you want to stora an attribute of the element)
The Target must be a css or an xpath expression which can localize the appropriate element
The Value is the name of the new local variable in your Selenium IDE script
After using store command you can use your new variable like this: ${yourNewVariable}
For example:
storeAttribute xpath=//div[#id='name-day']#name nameday
echo ${nameday}
You can use while loop and goto function in selenium ide with this addon : https://addons.mozilla.org/en-us/firefox/addon/flow-control/
Some commands:
gotoif
while
gotolabel
Example:
store 1 answers
while storedVars.answers <= 3
echo ${answers}
...
store javascript{storedVars.answers++;}
endWhile