I've got a couple of 20 a 25 working now.
This is another one I can't get to working:
*** Settings ***
Library Browser enable_presenter_mode=True
#Library XML
#Library Collections
#Library String
#Library DateTime
Documentation Scroll into view
*** Variables ***
*** Test Cases ***
Extracting text
Open Browser https://obstaclecourse.tricentis.com/Obstacles/99999
#sleep 3s
Browser.Focus css=iframe >>> input[id="textfield"]
sleep 1s
Type Text css=iframe >>> input[id="textfield"] Tosca
#Fill Text textfield Tosca
Click id=submit
sleep 3s
# used resources: https://robocorp.com/docs/development-guide/browser/how-to-work-with-iframes
The problem here is that It can't type in the section whilst it is not into view.
The weird thing is: I have seen it working once where it typed while the textarea was NOT even into view. But the problem is I closed that instance of VScode and I was not able to see how that was produced (very tricky) (but I know it is possible without being into view, yes strange)
Looked much things up.
I think this is almost it:
Browser.Scroll To css=iframe >>> input[id="textfield"] vertical=top
Related
I'm trying to create a FOR Loop in Robot Framework that will click through a set of links on a page. Trying to avoid a string of "Click Element" lines and just make a loop out of it. I believe my base code is correct in the loop construction, but PyCharm is seeing the first line of the loop as its own keyword, which isn't right. It's not moving past that part. Any ideas here?
My variables are known, just stored off on another file.
Documentation Homepage
Library Zoomba.GUILibrary
Library Process
Resource ../../Pages/resource.robot
Suite Setup Browser Setup ${url}
*** Keywords ***
Menu Navigation
${list}= Create List ${TUAbout} ${TUAcademics} ${TUResearch}
:FOR ${item} IN #{list}
Wait For And Click Element ${item}
END
*** Test Cases ***
TC 001 Menu Navigation
Menu Navigation```
You need at least 2 spaces for the variables on the FOR line and FOR syntax has changed in more recent versions of RF so :FOR is deprecated syntax use just FOR e.g.
FOR ${item} IN #{list}
I believe that should be enough to fix the current error you're seeing
The source is this obstacle: https://obstaclecourse.tricentis.com/Obstacles/87912
What I got this far is:
*** Settings ***
Library Browser
Library XML
Library Collections
Library String
Documentation BE FAST AUTOMATE
*** Variables ***
${links}= <isbn>
${rechts}= </isbn>
*** Test Cases ***
Execute a for loop only three times
Open Browser https://obstaclecourse.tricentis.com/Obstacles/87912
Click id=loadbooks
${alles}= Get Text id=books
This one is mentioned: 'hard'
The Get Text literally gets all the text which is fine, but from that point I have no clue how the get the isbn (from the specific, or even ... any)
A bit further thanks to this page: Parse XML only returns first element
*** Settings ***
Library Browser enable_presenter_mode=False
Library XML
Library Collections
Library String
Documentation BE FAST AUTOMATE
*** Variables ***
##{ROBOTS}= 1 2 3
${links}= <isbn>
${rechts}= </isbn>
*** Test Cases ***
Find the isbn
Open Browser https://obstaclecourse.tricentis.com/Obstacles/87912
sleep 5s
Click id=loadbooks
${alles}= Get Text id=books
${x}= Parse Xml ${alles}
${el_my_value}= XML.Get Element ${x} .//isbn
Log ${el_my_value}
${first_text}= Get Element Text ${el_my_value}
but now I still need the isbn corresponding to the correct title.
because the response is: Multiple elements (6) matching './/isbn' found.
I don't think I should post this as you are suppose to build the answer to the exercise, not google it...
Nevertheless, here it goes.
The data is hidden and if you carefully look into the html of the page you will see that after clicking the button "Load books" a javascript function is kicked that will set the value into the xml and into a variable.
After knowing this information is very simple to get the value that we want just using simple robot + selenium:
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Insert Correct ISBN
Open Browser https://obstaclecourse.tricentis.com/Obstacles/87912 Chrome
Click Element id=loadbooks
${isbnValue} Execute Javascript return isbn
Input Text id=isbn ${isbnValue}
I've a situation in my app where I need to click on file name from a /div table which will save the file name internally and gets displayed in a /div grid. Every time I run the automation, I need to click on a new file.
I don't have any problem in clicking the file to be saved.
But after the click, the app stores the file in a /div grid and I want to select the file that I added.
For this I used this approach:
I am storing the file name in a global variable ${g_ExtractedFileName}
For eg: XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt
My complete Xpath to the file is something like this
xpath://div[#role='row']//span[contains(text(),'XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt')]
For this I have the below:-
${attachedFileXpath1}= set variable xpath://div[#role='row']//span[contains(text(),'
${attachedFileXpath2}= set variable ${g_ExtractedFileName}
${attachedFileXpath3}= set variable ')]'
${attachedFileXpath}= set variable ${attachedFileXpath1}${attachedFileXpath2}${attachedFileXpath3}
click element ${attachedFileXpath}
This throws an error
SyntaxError: Failed to execute 'evaluate' on 'Document': The string
'//div[#role='row']//span[contains(text(),'XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt
')]'' is not a valid XPath expression.
When I don't use the variables and simply use (hard coded value for file name)
click element xpath://div[#role='row']//span[contains(text(),'XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt')]
It works correctly.
I also tried this but same error
${attachedFileXpath}= catenate ${attachedFileXpath1}${attachedFileXpath2}${attachedFileXpath3}
I am not sure when the 3 variables are concatenated, it cuts off the variable value to a new line causing this problem.
Any help is much appreciated.
The simplest approach is to simply use the replace functionality that is already present in Robot Framework variables. The below example will result in an Element not found error, but that is expected.
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${g_ExtractedFileName} XX_YY_Response_IdNum_48015_2020-07-27T12-18-44.334442.txt
*** Test Cases ***
Use Global String in Locator
Open Browser https://google.com chrome
click element xpath://div[#role='row']//span[contains(text(),'${g_ExtractedFileName}')]
[Teardown] Close All Browsers
Simply create keyword which accept the file name as argument and returns complete valid xpath expression. It will be re-usable and elegant solution -
*** Test case ***
Select file saved in div grid
${attached_file_xpath}= GetAttachedFileXpath ${File_Name}
Click Element ${attached_file_xpath}
*** Keywords ***
GetAttachedFileXpath [Arguments] ${File_Name}
return from keyword xpath://div[#role='row']//span[contains(text(),'${File_Name}')]
As part of a Robot Framework test I would like to access multiple objects from my page with the same keyword. The xpath of the objects looks like this:
//div[#class='col-sm-4 ng-scope']//h1[#class='ng-binding'][contains(text(),'Bot1')]
//div[#class='col-sm-4 ng-scope']//h1[#class='ng-binding'][contains(text(),'Bot2')]
//div[#class='col-sm-4 ng-scope']//h1[#class='ng-binding'][contains(text(),'Botx')]
I've tried to set a list variable with the name of my test objects (elements)
*** Variables ***
#{TESTBOTS} = Bot1 Bot2 Botx
*** Keywords ***
Delete Bots
go to ${LANDINGURL}
Sleep 3s
Click Element //div[#class='col-sm-4 ng-scope']//h1[#class='ng-binding'][contains(text(), #{TESTBOTS})]
However, I get the following error:
FAIL Element with locator '//div[#class='col-sm-2 ng-scope']//h1[#class='ng-binding'][contains(text(),'${TESTBOTS')]' not found.
I'd really appreciate if you could point me to the right direction. Thanks!
The error message still does not seem to fit the snippet, I believe.
But anyway: with #{TESTBOTS} you unwrap the complete list. I would have expect an error like No element found with text 'Bot1 Bot2 Botx'
I think this should work iterating the list of testbots:
FOR ${testbot} IN #{TESTBOTS}
Click Element //div[#class='col-sm-4 ng-scope']//h1[#class='ng-binding'][contains(text(), ${testbot})]
END
I have a project in RobotFramework that already have more than 50 tests created. And I want to use AppiumLibrary or Selenium2Library according a type of test. I would like to avoid have the same test repeated, just because the Selenium2Library don't work on Mobile
*** Settings ***
Library AppiumLibrary
Library Selenium2Library
*** Test Cases ***
TC001
[Setup] Configuration
Pause Execution ${globalType}|${globalLibrary}
Start Test
${globalLibrary}.Wait Until Page Contains Element id=age-gate-yes 60s
Sleep 3s
${globalLibrary}.Click Element xpath=//a[#id='age-gate-yes']
${globalLibrary}.Wait Until Page Contains Element xpath=//a[#href="/profile"] 60s
${globalLibrary}.Click Element xpath=//a[#href="/profile"]
${globalLibrary}.Wait Until Page Contains Element xpath=//input[#name="email"] 60s
${globalLibrary}.Click Element xpath=//input[#name="email"]
${globalLibrary}.Input Text xpath=//input[#name="email"] johndoe#john.doe
${globalLibrary}.Click Element xpath=//input[#name="password"]
${globalLibrary}.Input Text xpath=//input[#name="password"] JohnDoe123
${globalLibrary}.Click Element xpath=//div[#id='react-component-login-header']//button/div/span[1]
${globalLibrary}.Wait Until Page Does Not Contain Element xpath=//div[#id='react-component-login-header']//button/div/span[1] 15s
[Teardown] End Test
*** Keywords ***
Configuration
Set Global Variable ${globalType} ${Type}
Run Keyword If '${Type}'=='Desktop' Set Global Variable ${globalLibrary} Selenium2Library
Run Keyword If '${Type}'=='Mobile' Set Global Variable ${globalLibrary} AppiumLibrary
Pause Execution ${globalType}|${globalLibrary}
Start Test
Run Keyword If '${Type}'=='Desktop' Start Desktop
Run Keyword If '${Type}'=='Mobile' Start Mobile
End Test
Run Keyword If '${Type}'=='Desktop' End Desktop
Run Keyword If '${Type}'=='Mobile' End Mobile
Start Mobile
AppiumLibrary.Open Application http://127.0.0.0:4444/wd/hub platformName=iOS platformVersion=12.1 deviceName=iPhone Simulator browserName=Safari
AppiumLibrary.Go To Url https://www.somewebsite.com/
Start Desktop
Selenium2Library.Open Browser https://www.somewebsite.com/ Chrome
Maximize Browser Window
End Mobile
Close All Applications
End Desktop
Close All Browsers
I was hoping that the global variable could fullfill the Library, however I am getting:
TC001 | FAIL |
No keyword with name '${globalLibrary}.Wait Until Page Contains Element' found. Did you mean:
AppiumLibrary.Wait Until Page Contains Element
Instead of putting the library name in a variable, you can instantiate the needed library dynamically using Import Library (from Builtin):
Configuration
Run Keyword If '${Type}'=='Desktop' Import Library Selenium2Library
Run Keyword If '${Type}'=='Mobile' Import Library AppiumLibrary
This way, it will be flexible as you want, either for desktop or mobile tests.