No Browser is Open issue is coming when running the Robot framework script

2024/10/6 5:56:32

I have created Test.py file which has some function in it and using those function names as Keywords in sample.robot file.

Ex: - Test.py

def Launch_URL(url):driver.get(url)def article(publication):   do something here

Sample.robot

Library  Selenium2Library
Library  Test.py*** Test Cases ****Open app     Launch URL   "https://stackoverflow.com"article       somethingClick Element  xpath=/html/body/div[1]/div/div/button/i

Apart from the derived keywords in .py I also want to use built in Keyword Click Element in robot file. When the I run the above script it is throwing me No Browser Open error for Click Element keyword.

Answer

The click element keyword (and all of the other keywords) relies on a browser opened by Selenium2Library. Since you are opening it with the python selenium module rather than the robot library, the Selenium2Library keywords do not know about the browser.

If you need to use the same browser both for Selenium2Library and through python code, The best way is to open the browser with Selenium2Library, and then get the driver reference from it to use it in python.

Assuming that you've opened the browser using the open browser or create webdriver keyword, you can use the driver for that browser in python like this:

from robot.libraries.BuiltIn import BuiltIn
def Launch_URL(url):se2lib = BuiltIn().get_library_instance('Selenium2Library')driver = se2lib._current_browser()driver.get(url)

If you do not want to use open browser in your test, and expect Launch URL to be the first keyword you use, you can call open_browser from your keyword:

def Launch_URL(url):se2lib = BuiltIn().get_library_instance('Selenium2Library')se2lib.open_browser(url, "chrome")

Here's another similar question: Pass existing Webdriver object to custom Python library for Robot Framework

If you are wanting to write keywords in python that use both the built-in keywords and also have directly access to the selenium module, you might want to consider using this page object library, which handles all of the details for you.

Note: the use of the private method _current_browser is unavoidable in version 2 of Selenium2Library. A public interface is being made available in version 3 of SeleniumLibrary. See github issue #882

https://en.xdnf.cn/q/118984.html

Related Q&A

How to run python file in Tkinter

Im a beginner in Python, hence the question. i would like to run a python file (smileA.py) in Tkinter. How would i start? I do not wish for it to run when clicking a button, but the file to run automa…

Discord.py Cogs “Command [ ] is not found”

I am recoding my discord.py bot using cogs as it wasnt very nice before. I tried this code: import discord import os import keep_alive from discord.ext import commands from discord.ext.commands import …

Binomial distribution CDF using scipy.stats.binom.cdf [duplicate]

This question already has answers here:Alternatives for returning multiple values from a Python function [closed](14 answers)Closed 2 years ago.I wrote below code to use binomial distribution CDF (by u…

How to get Cartesian product of two iterables when one of them is infinite

Lets say I have two iterables, one finite and one infinite:import itertoolsteams = [A, B, C] steps = itertools.count(0, 100)I was wondering if I can avoid the nested for loop and use one of the infinit…

Function to create nested dictionary from lists [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Pygame not using specified font

So I am having a problem in pygame where I specify the font and size to use, but when my program is run, the font and size are the default.Here is where I define the textdef font(self):*****FATAL - THI…

port management in python/flask application

I am writing a REST API using the micro framework Flask with python programming language. In the debug mode the application detect any change in source code and restart itself using the same host and p…

using def with tkinter to make simple wikipedia app in python

I am beginner in python. I am trying to make a python wiki app that gives you a summary of anything that you search for. My code is below:import wikipediaquestion = input("Question: ")wikiped…

Only length-1 arrays can be converted to Python scalars with log

from numpy import * from pylab import * from scipy import * from scipy.signal import * from scipy.stats import * testimg = imread(path) hist = hist(testimg.flatten(), 256, range=[0.0,1.0])[0] hist…

Deploying Django with apache using wsgi.py

Im trying to deploy a Django project on a linode server that has apache, some other django projects and a php project on it. Also my project is in a virualenv and the other django projects arent.My Dja…