RobotFramework "input text" does not let access text

1.4k views Asked by At

I am learning robot framework and all I'm trying is to search for a video but i get stuck on inserting text in search bar, with error:

InvalidElementStateException: Message: Unable to clear element that cannot be edited:

(Error occurs in the very last line of below code)

More specific, I am trying to open Youtube in firefox, (accept the cookies) and then click on search bar, it clicks but the text is not inserted.

what i managed until now:

*** Settings ***

Library    SeleniumLibrary

*** Variables ***

${Browser}  firefox
${url2}    https://www.youtube.com/


*** Test Cases ***
Trololo
    ReallyDontOpen          #Open Browser
    maximize browser window         #Maximize windows
#    run keyword if    Check for Cookies popup    Close YoutubeCookies     
    Close YoutubeCookies        #Accept youtube cookies
    Search For Magic    


    #close browser


*** Keywords ***
ReallyDontOpen
    open browser    ${url2} ${Browser}

Check for Cookies popup     #unused until fixing IF statement
    wait until element contains    xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1    Before accessing YouTube

Close YoutubeCookies
    wait until element contains    xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1    Before accessing YouTube
    click element    xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/form[2]/div/div/button/span


Search For Magic    
    click element    xpath://*[@id="search-form"]
    clear element text    xpath://*[@id="search"]
    input text    xpath://*[@id="search"]    rick roll 10 hours

I tried all kind of IDs around that search bar but nothing works... Thank you in advance!

1

There are 1 answers

2
Fayaz On

Replace your last line with this code: input text xpath://input[@id="search"] rick roll 10 hours

Remove this line no need to clear: clear element text xpath://*[@id="search"]

Below is my working code

*** Settings ***

Library    SeleniumLibrary

*** Variables ***

${Browser}  firefox
${url2}    https://www.youtube.com/


*** Test Cases ***
Trololo
    ReallyDontOpen          #Open Browser
    maximize browser window         #Maximize windows
    #run keyword if    Check for Cookies popup    Close YoutubeCookies
    Close YoutubeCookies        #Accept youtube cookies
    Search For M`enter code here`agic


    #close browser


*** Keywords ***
ReallyDontOpen
    open browser    ${url2} ${Browser}

Check for Cookies popup     #unused until fixing IF statement
    wait until element contains    xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1    Before accessing YouTube

Close YoutubeCookies
    wait until element contains    xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/h1    Before accessing YouTube
    click element    xpath:/html/body/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/form[2]/div/div/button/span


Search For Magic
    input text    xpath://input[@id="search"]    rick roll 10 hours