How to Change the display Properties of a button using Javascript in robot Framework

360 views
Skip to first unread message

Trusha P

unread,
Mar 26, 2021, 12:37:51 PM3/26/21
to robotframework-users
Hi Team,

I am new to Robot framework and selenium. I  am stuck in changing the display Property of an checkbox .Pls help me out. Thank You all In advance.
Below is my element:

HTML_CODE.PNG
Her display property is et to : none.How to change this in robot framework selenium.

I Tried below and getting failed.
Execute Javascript var btn = document.getElementById('notification-checkbox-sendnow').style.display = 'block';

Error:
ERROR.PNG

I have below sample code but not able to understand:
Execute Javascript var btn = document.getElementById('_edit_file_upload_button'); var fileId = document.getElementById(btn.getAttribute('for'));fileId.style.display = 'block'; sleep ${SLEEP_TIME} 
Choose File ${UPLOAD_FILE_LIST_ID} ${REVISION_PROJECT_FILE_NAME} 
sleep ${SLEEP_TIME} 
Execute Javascript var btn = document.getElementById('fupload');btn.style.display = 'none'; sleep ${SLEEP_TIME}

Regards,
TP

Dave Amies

unread,
Mar 27, 2021, 7:00:54 AM3/27/21
to robotframework-users
Hi TP,

I'll start with the question: would the user of the web site normally execute this javascript on the page themselves? Guessing the answer is probably no, they would actually click an element that looks like a check box on the page?

I suggest you first try to make robot framework click the element the user would click and let the javascript in the page respond to that event and execute what it needs to.

The reason I worded it the way I did is sometimes the form element you are trying to use the javascript to click is not visible on the page and actually actioned by in page javascript, There is usually a div or span element that has been styled by css to look like a button or checkbox that the user would interact with and in my experience its far better to just get RF to interact with this span/div element as the user would rather than trying to execute some javascript, which should really be your last resort.

so for your html example above I would try:

`Click Element    xpath://label/span/span[contains(text(), "Send Immediately")]`

Hope that helps,

Dave.

Reply all
Reply to author
Forward
0 new messages