2017-05-02 8 views
1

Excelシートからデータをインポートし、そのパラメータをPythonスクリプトに渡そうとしています。このスクリプトでは、「ブラウザ」をExcelファイルのパラメータとしても使用しようとしています。以下はその詳細です。ドライバの代わりにwebdriverにパラメータを渡す

ブラウザはExcelシートの "B2" のセルに指定されている:

enter image description here

ワークブック名​​: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) 
+0

あなたのExcelのB2値には、より近い "()"がない可能性があります。 –

答えて

0

私は思いますウェブドライバの作成にはより近いものが必要ですが、近いうちに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() 
+1

上記のステートメントを直接実行しようとするとエラーが発生したため、以下で使用しています。先端をありがとう... WB = openpyxl.load_workbook( 'Data.xlsx') コンフィグ= wb.get_sheet_by_name( '設定') B1 = configの[ "B2"]。値 場合B1 ==」クローム ': ブラウザ= webdriver.Chrome() ELIFのB1 ==' Firefoxの ': ブラウザ= webdriver.Firefox() ELIFのB1 ==' IE ': ブラウザ= webdriver.Ie() – Sriniwaas

+0

ザッツ朗報!私はあなたのコメントを反映するために私の答えを更新します –

+0

私は間違いを見て、私は 'value'の代わりに' value() 'を行いました。私は答えが良いと思う –

関連する問題