如何使用Selenium WebDriver和Python处理国际化?

2024-05-07 01:21:29 发布

您现在位置:Python中文网/ 问答频道 /正文

有谁能举个例子告诉我如何用selenium webdriver和Python来处理国际化问题吗。在

找到了这篇文章,但它是用Java编写的

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

寻找一种使用Web驱动程序+Python组合的方法。在


Tags: httpscomwebuiseleniumwordpressjavalocalized
1条回答
网友
1楼 · 发布于 2024-05-07 01:21:29

以下代码的国际化示例:

使用编辑器:PyCharm

文件名:国际化.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文件:测试套件.csv在

此文件包含打开网站所用语言的名称。在

文件结构:

^{pr2}$

读取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

欢迎反馈!在

相关问题 更多 >