Open Browser http://www.sit.edptest.info/edphome/home.aspx/ firefox
set selenium timeout 10 seconds
Comment Count Number Of Linkds on the Page
${AllLinksCount}= Get Matching Xpath Count //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}
\ ${lintext}= Get Text xpath=(//a)[${INDEX}]
\ ${href}= Get Element Attribute xpath=(//a)[${INDEX}]@href
\ Log ${lintext}
\ log to console ("link text " ${lintext}"href " ${href} ${INDEX})
\ ${linklength} Get Length ${lintext}
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${lintext}
${linkitems_length} Get Length ${LinkItems}
@{errors_msg} Create List
:FOR ${INDEX} IN range ${linkitems_length}
\ go to ${your site}
\ click element ${LinkItems[${INDEX}]}
\ Capture Page Screenshot
Suite Teardown Run Keyword And Ignore Error Close All Browsers
Library Selenium2Library
Library Collections
Library requests
Crowler 2
Open Browser http://www.google.com firefox
set selenium timeout 10 seconds
Comment Count Number Of Linkds on the Page
${AllLinksCount}= Get Matching Xpath Count //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}
\ ${lintext}= Get Text xpath=(//a)[${INDEX}] #<-- for what ? -->
\ ${href}= Get Element Attribute xpath=(//a)[${INDEX}]@href
\ Log ${lintext}
\ log to console ("link text " ${lintext}"href " ${href} ${INDEX})
\ ${linklength} Get Length ${lintext} #<-- you are checking text not href ? -->
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${href}
Log Many ${LinkItems}
Comment Remove Values From List ${LinkItems} javascript:void(0) #<-- don't forget checking content on list -->
${linkitems_length} Get Length ${LinkItems}
@{errors_msg} Create List
:FOR ${INDEX} IN range ${linkitems_length}
\ ${ret} requests.Request Get ${LinkItems[${INDEX}]}
\ ${code} Run Keyword And Return Status Should Be Equal As Strings ${ret.status_code} 200
\ 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}
*** Settings ***
Suite Teardown Run Keyword And Ignore Error Close All Browsers
Library Selenium2Library
Library Collections
Library requests
CrowlerV2
@{errors_msg} Create List
Selenium2Library.Open Browser http://www.google.com ff
@{hrefs} Create List
${items} Get Matching Xpath Count //body//a
: FOR ${item} IN RANGE ${items}
\ ${href} Selenium2Library.Get Element Attribute //body/descendant::a[${item+1}]@href
\ log ${href}
\ Append To List ${hrefs} ${href}
Log List ${hrefs}
Remove Values From List ${hrefs} javascript:void(0) \#
${linkitems_length} Get Length ${hrefs}
:FOR ${item} IN range ${linkitems_length}
\ ${flag} ${ret} Run Keyword And Ignore Error requests.Request Get ${hrefs[${item}]}
\ ${code} Run Keyword And Return Status Run Keyword If '${flag}'=='PASS' Should Be Equal As Strings ${ret.status_code}
\ ... 200
\ Run Keyword Unless ${code} Append To List ${errors_msg} error :${hrefs[${item}]} | ${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}Suite Teardown Run Keyword And Ignore Error Close All Browsers
*** Settings ***
Library Selenium2Library
Library Collections
Library SauceLabs
Library requests
*** Test Cases ***
Get All Links
[Tags] Links
Open Browser http://www.sit.edptest.info/edphome/home.aspx# firefox
set selenium timeout 10 seconds
Comment Count Number Of Linkds on the Page
${AllLinksCount}= Get Matching Xpath Count //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}
\ ${lintext}= Get Text xpath=(//a)[${INDEX}] #<-- for what ? -->
\ ${href}= Get Element Attribute xpath=(//a)[${INDEX}]@href
\ Log ${lintext}
\ log to console "link text " ${lintext}"href "${href} ${INDEX}
\ ${linklength} Get Length ${lintext} #<-- you are checking text not href ? -->
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${href}
Log Many ${LinkItems}
Comment Remove Values From List ${LinkItems} javascript:void(0) #<-- don't forget checking content on list -->
${linkitems_length} Get Length ${LinkItems}
@{errors_msg} Create List
:FOR ${INDEX} IN range ${linkitems_length}
\ ${ret} requests.Request Get ${LinkItems[${INDEX}]}
\ log to console $(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
#\ Selenium2Library.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}
The first link click gave me this errorValueError: Element locator 'http://www.sit.edptest.info/edphome/home.aspx' did not match any elements.