2017-05-02 8 views
1

Excel 시트에서 데이터를 가져 와서 해당 매개 변수를 Python 스크립트에 전달하려고합니다. 여기서 "브라우저"도 Excel 파일의 매개 변수로 사용하려고합니다. 다음은 세부 사항입니다.대신 드라이버 webdriver에 매개 변수를 전달합니다.

브라우저는 엑셀 시트의 "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

엑셀 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

위의 문장을 직접 시도하면 오류가 발생하므로 아래에서 사용하고 있습니다. 팁에 감사드립니다 ... openpyxl.load_workbook WB = ('Data.xlsx') 구성 wb.get_sheet_by_name = ('구성') B1 = 설정 [ "B2"]. 값 경우 B1 == ' 크롬 ' 브라우저 = webdriver.Chrome() ELIF의 B1 =='파이어 폭스 ' 브라우저 = webdriver.Firefox() ELIF의 B1 =='IE ' 브라우저 = webdriver.Ie() – Sriniwaas

+0

그게 좋은 소식! 귀하의 의견을 반영하도록 답변을 업데이트하겠습니다. –

+0

실수를 저질렀습니다. 'value'대신 'value()'를 사용했습니다. 나는 그 대답이 지금 좋다고 생각한다. –