任何人都可以通过一个例子向我建议如何使用selenium webdriver和Python处理国际化。
发现这篇文章,但它是用Java
寻找使用Web Driver + Python组合的方法。
答案 0 :(得分: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
此文件包含我们要在其中打开网站的语言的名称。
档案结构:
Language
pt-BR
fr
读取csv文件的方法:
将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
非常欢迎反馈!