2016-12-26 14 views
0

selenium webdriverとPythonで国際化を処理する方法を例を挙げて教えてください。Selenium WebDriverをPythonで使用して国際化を処理する方法は?

は、この記事を見つけたが、それは、Java

ウェブドライバー+ Pythonの組み合わせを使用してのアプローチを探してい

https://nileshdk.wordpress.com/2013/08/06/internationalization-automating-localized-ui-using-selenium-webdriver/

です。コードの下での国際化のための

+0

この記事には、非常に単純なコードニッペクトが5行あり、言語に依存していません。Pythonでもまったく同じように見えます。現在の言語に基づいて動的にテキスト・リストをロードするだけで、好きなように指定することができます。 – skandigraun

+1

'# - * - coding:utf-8 - * - 'を 'script.py'の先頭に追加してみてください。これはあなたが '' utf-8 ''エンコーディングを使用できるようにすべきです – Andersson

答えて

0

例:

エディタを使用:PyCharm

ファイル名を:Internationalization.py

from selenium import webdriver 
from Day_3.csvReader import * 

for languages in test_execution(): 

    firefoxprofile = webdriver.FirefoxProfile() 
    firefoxprofile.set_preference("intl.accept_languages", languages) 

    driver = webdriver.Firefox(firefoxprofile) 
    driver.maximize_window() 
    driver.get("http://www.google.com") 

    text_leftbottom1 = ".//*[@id='fsl']/a[" 
    text_leftbottom2 = "]" 

    for i in range(1, 4): 
     for linktext in driver.find_elements_by_xpath(text_leftbottom1 + str(i) + text_leftbottom2): 
      print(linktext.text) 

    text_rightbottom1 = ".//*[@id='fsr']/a[" 
    text_rightbottom2 = "]" 

    for i in range(1, 3): 
     for linktext in driver.find_elements_by_xpath(text_rightbottom1 + str(i) + text_rightbottom2): 
      print(linktext.text) 

は、CSVファイル:testsuite.csv

このファイルには名前が含まれています私たちがサイトを開こうとする言語のファイルの

構造:CSV

def test_execution(): 
    with open('E:\\Study\\HackerRank_30DaysofCode\\Day_3\\testsuite.csv', 'r+') as file: 
     data = csv.DictReader(file) 
     result = [] 
     for row in data: 
      result.append((row['Language'])) 
     return result 

フィードバック大歓迎として

インポートCSV:CSVファイルを読み込むための

Language 
pt-BR 
fr 

方法!

関連する問題