簡體   English   中英

將參數傳遞給webdriver而不是驅動程序

[英]passing parameter to webdriver instead of driver

我試圖從Excel工作表導入數據並將其作為參數傳遞給python腳本,我也試圖將“瀏覽器”也作為excel文件中的參數。 以下是詳細信息。

瀏覽器在excel表的“B2”單元格中指定:

在此輸入圖像描述

工作簿名稱:Data.xlsx

工作表名稱:配置

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)

我認為這是因為創建webdriver需要更接近,但是你試圖將一個字符串放在webdriver的末尾而沒有更近(更接近括號“()”的結尾)。 嘗試使用這個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM