use of "Execute Javascript" Selenium2Library to retrieve value - robotframework

Using the below script to retrieve value by passing WebElement as argument in javascript:
${elem}=Get WebElement name=productField
${value}=Execute Javascript return document.arguments[0].value,'${elem}';
Log To Console ${value}
Seeing the below error:
WebDriverException: Message: unknown error: Cannot read property '0' of undefined

In the SeleniumLibrary documentation there are two keywords that useful in this situation: Get Text and Get Value. Both take your identifier as input and return the desired text.
${text}= Get Text name=productField
${value}= Get Value name=productField
So, there is no need to use javascript for this.

Related

How do I get hidden text from text field by robotframework

I used this statement but got error
${searchbox_title} Get Text //form[#role='search']//input[#aria-label='ค้นหาใน เสื้อผ้าแฟชั่นผู้ชาย']
Error msg
Element with locator '//form[#role='search']//input[#aria-label='ค้นหาใน เสื้อผ้าแฟชั่นผู้ชาย']' not found.
You seem to be trying to get the value from a dynamic element. The input field has that content after being written by the user or robot. Why not trying a different locator, for example:
//form[#role='search']/input[#class='shopee-searchbar-input___input']

How to include dictionary creation into Run Keywords in robot framework

I'm trying to use combination Run Keywords and Create Dictionary built-in keywords
This code:
Run Keywords
... &{dict} Create Dictionary ${data}
returns:
Variable '&{dict}' not found.
any ideas?
message
Run Keyword specifically designed to be used in setup or tear down methods where creating an user defined keyword is an Overkill. User defined keyword does the same thing as Run Keywords but additionally it can return you the values from the enclosing keywords.
Here is the Run Keywords documentation
Coming to the problem. Run keyword will treat any variable argument as keyword unless it is not the parameter of the keyword using AND operator. In the error - &{dict} it is searching for the variable but it is not found. hence the error. Following code demonstrate the behavior of Run keywords
***Variable
${keyword}= comment something
***Testcase
Test1
Run Keywords ${keyword}
***Keyword
comment something
log This is comment
Output -
Actual resolution -
Define new keyword and enclose the keywords of your requirement and call the user defined keyword.
***Keyword
User Defined Keyword [Arguments] ${key} ${value}
&{dict}= Create Dictionary ${key} ${value}
Return from keyword ${dict}
*** Testcase
User Keyword Demo
&{dict}= User Defined Keyword name=xyz
Log ${dict}
Output =

I want to check if a div has a specific ID and class robot framework

I want to check if the page contains an element with a specific id and a class:
${is_court_selected}= Run Keyword And Return Status Wait Until Page Contains Element //div[#id="card_for_court_${position_1}",contains(#class,'selected_court_subtab_courts')] ${TIMEOUT AJAX}
I get the following error code:
InvalidSelectorException: Message: Given xpath expression "//div[#id="card_for_court_15",contains(#class,'selected_court_subtab_courts')]" is invalid: SyntaxError: The expression is not a legal expression.
At least add first locator strategy: xpath: //div[#id="card_for_court_${position_1}",contains(#class,'selected_court_subtab_courts')]
also you might need to replace the ,in xpath by and:
xpath: //div[#id="card_for_court_${position_1}" and contains(#class,'selected_court_subtab_courts')]

Robot Framework - Keywords after [Return] line are also executing

Set of instructions which are written after [Return] statement are getting executed. Robot Framework should through an error or should not consider the keywords written after [Return] keyword. Please give explanation if I missed something.
Settings
Variables
Keywords
Custom Keyword
[Return] hyyyy
Return From Keyword hyyyy2222
Test Cases
Test1
${var_rt_ky2}= Custom Keyword
Log To Console ${var_rt_ky2}
Output:
hyyyy2222
In other case
Settings
Variables
Keywords
Custom Keyword
Return From Keyword hyyyy2222
[Return] hyyyy
Test Cases
Test1
${var_rt_ky2}= Custom Keyword
Log To Console ${var_rt_ky2}
Output:
hyyyy
This is how robot is designed to work. [return] merely defines the return value, it doesn't cause the keyword to return when it is called.
If you want to explicitly return from a function you need to use one of the keywords from the built-in library (e.g. Return from keyword or Return from keyword if, etc. )

data-translate in data-bind not working

I am a newbie to knockout.js. I am having a problem. I am trying to translate the windowTitle in my html but I am getting an error. I can see the the window title when I do console.log(data.windowTitle); but i also get the following error in my console
Error: Unable to parse bindings. Message: SyntaxError: missing : after property id; Bindings value: attr{data-translate:windowTitle}
That is how I am trying to do my job
<span data-bind="attr:{data-translate:windowTitle}"></span>
The data-translate is not a valid javascript identifier. You need to wrap the identifier name in quotes ('') to make it work
<span data-bind="attr:{ 'data-translate' :windowTitle}"></span>
See also in the documentation: Applying attributes whose names aren’t legal JavaScript variable names

Resources