1

I have the following python file OpenBrowser.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options



def openit(browser):

chrome_options = Options()
chrome_options.add_argument("--headless")

desired_capabilities = chrome_options.to_capabilities()
desired_capabilities['acceptInsecureCerts'] = True


driver = webdriver.Chrome()
#driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe", chrome_options=chrome_options,desired_capabilities=desired_capabilities)
driver.get("http://www.python.org")

return browser

and a robot file:

*** Settings ***
Documentation    Suite description
Library        OpenBrowser.py

*** Test Cases ***
Test title
    openit  browser

The browser is open, but then it closes and if I want to run another keyword in RF I get error: No brpwser is open

How can I run the python function and keep the browser open?

mrsmith
  • 11
  • 2
  • Is the commented line in your example of any use? If not, van you remove it for clarity? Can you highlight why you want to open the browser from Python and not use the [standard keywords](https://stackoverflow.com/questions/46812155/how-to-run-headless-remote-chrome-using-robot-framework/46817149#46817149) for creating capabilities or the [standard functionality](http://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Open%20Browser) for running headless? – A. Kootstra Nov 09 '18 at 12:09
  • Hello A. Kooststr, yes I will use it in the future. I want to run this python keyword and not the standard one from RF, because I have a website that doesn't have trusted cerificates and I saw that I can open it headless using desired capabilities. But now I stuck because the page that I open with python keyword doesn't remain open. It doesn't behave like Open Browser keyword from RF. – mrsmith Nov 09 '18 at 12:39
  • No, it's not working to open not even your url. Maybe is something wrong in my setup. – mrsmith Nov 12 '18 at 09:32

1 Answers1

1

From the top of my head this should allow you to do what you want:

*** Settings ***
Library    SeleniumLibrary

Suite Teardown    Close All Browsers

*** Test Cases ***
TC
    # Options for startin Chrome
    ${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver

    Call Method    ${chrome_options}    add_argument    headless
    Call Method    ${chrome options}    add_argument    ignore-certificate-errors

    # Arguments for starting ChromeDriver
    @{service_args}    Create List
        ...                --verbose
        ...                --log-path=${EXECDIR}/chromedriver.log

    Create Webdriver    Chrome    chrome_options=${chrome_options}    service_args=${service_args} 

    Go To    https://self-signed.badssl.com/

    Capture Page Screenshot

The service arguments will instruct ChromeDriver to generate a log file for you in the directory where you start Robot Framework. This may help with the analysis.

mercator
  • 28,290
  • 8
  • 63
  • 72
A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
  • Ok, thanks. But now, in my page I have a form and I want to Input Text using the id of the locator. But I get the error that the locator was not found. Or when I write Get Title looks like the title is the name of the robot file...… – mrsmith Nov 09 '18 at 13:19
  • Is the same situation, after it is open it is closed. – mrsmith Nov 09 '18 at 13:26
  • Yes: No browser is Open. The problem is that my url doesn't open at all, I can see from the screenshot that is a blank page, something like it couldn't open it, maybe because of the certs. – mrsmith Nov 09 '18 at 14:38
  • I've updated the example to allow for the generation of ChromeDriver log. Perhaps this helps with your analysis. – A. Kootstra Nov 12 '18 at 07:17
  • Hi, The error I get is: "unreachableUrl": "MY URL", "url": "chrome-error://chromewebdata/". If I comment the line #Call Method ${chrome_options} add_argument headless , the browser is open and it works fine, but I want to run it in headless mode...… – mrsmith Nov 12 '18 at 08:44
  • Which version of Chrome, Chrome Driver, Python Module SeleniumLibrary, Python Module Selenium are you running? – A. Kootstra Nov 12 '18 at 08:57
  • Python 2.7.13, ChromeDriver 2.41.578737, Chrome Version 70.3.3538, SeleniumLibrary 3.0, Selenium 3.14. The issues is that if I run this test with your url it works. I don't know why it doesn't worlk with my url………. – mrsmith Nov 12 '18 at 09:23