[英]passing parameter to webdriver instead of driver
I am trying to import data from excel sheet and pass that as parameter to python script, where i am also trying to take the "Browser" also as parameter from the excel file. 我试图从Excel工作表导入数据并将其作为参数传递给python脚本,我也试图将“浏览器”也作为excel文件中的参数。 Below are the details.
以下是详细信息。
The browser is specified in "B2" cell of the excel sheet: 浏览器在excel表的“B2”单元格中指定:
WorkBook name: Data.xlsx 工作簿名称:Data.xlsx
Sheet Name: Configuration 工作表名称:配置
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.expected_conditions import alert_is_present
import openpyxl
wb=openpyxl.load_workbook('Data.xlsx')
config=wb.get_sheet_by_name('Configuration')
'''b1=config["B2"].value'''
url=config["B3"].value
uid=config['B4'].value
pwd=config['B5'].value
Browser=webdriver.config['B2'].value()
'''in the above deceleration I am trying to pass the value from excel sheet, instead of writing the value directly. So from next time on wards, I can update in excel sheet with the required browser'''
class Actions():
def OpenApplication():
Browser.get(url)
I think it's because creating the webdriver needs a closer, but you're trying to put a string on the end of webdriver
without a closer (closer are the parentheses "()" at the end). 我认为这是因为创建webdriver需要更接近,但是你试图将一个字符串放在
webdriver
的末尾而没有更近(更接近括号“()”的结尾)。 try using this if
statement. 尝试使用这个
if
语句。
wb=openpyxl.load_workbook('Data.xlsx')
config=wb.get_sheet_by_name('Configuration')
b1=config["B2"].value
if b1 == 'Chrome':
Browser = webdriver.Chrome()
elif b1 == 'Firefox':
Browser = webdriver.Firefox()
elif b1 == 'IE':
Browser = webdriver.Ie()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.