我正在尝试自动化一个网站,该网站也有一个法语网站的链接。当我启动这个法语网站时,所有产品描述、货币等都会变成法语。 我的问题与使用 WebDriver 自动化这个法国网站有关。
目前,我正在将法语单词(产品名称/其描述等)作为普通字符串传递给我的 Java Selenium 代码,它似乎可以工作。
测试代码似乎有效:
WebElement el = driver.findElement(By.id("nav-nouveautes"));
String str = el.findElement(By.className("highlight")).getText();
String searchItem = "Tri, table d'appoint, frêne naturel";
driver.findElement(By.id("search")).sendKeys(searchItem);
driver.findElement(By.className("btns search")).click();
这是自动化非英语站点的正确方法吗 - 按原样传递字符串并以相同的方式检索文本?在一些链接中,他们提到将浏览器的区域设置更改为特定语言。有必要吗? 尝试谷歌搜索,但找不到好的答案。
我正在考虑使用 FitNesse 来编写测试
这是 html 源代码的几个片段:
<label for="search" style="display:none;">Recherche :</label>
<input id="search" name="q" value="" class="input-text" />
<!--
<button type="submit" title="Recherche" class="button"><span><span>Recherche</span></span></button>
-->
<button class="btns search" type="submit">
</button>
<div id="slide_one" class="xxxxxxWorksSlide">
<p id="slideOne_title">En boutique, un fauteuil de designer <br> se vend en général</p>
<span class="price-dashed" id="slideOne_left"></span>
<p id="slideOne_price">1 500 €</p>
<span class="price-dashed" id="slideOne_right"></span>
<p id="slideOne_copy">Son design a de quoi vous xxx. Mais sa fabrication coûte seulement 250 €. Soit une marge de 500 %.</p>
<a id="slideOne_btns" class="btns" title="" href="#"><span class="button_label">xxx change les règles<span class="chevron">»</span></span></a>
</div>
抱歉,如果这是一个非常愚蠢的问题。 感谢您查看我的帖子。
最佳答案
Is this the right way to automate a non-english site - passing strings as it is and retrieving the text in the same way ?
这并没有错。我个人认为这是最简单的方法,但您需要确保所有文件的编码都是 UTF-8,否则其他人查看您的文件时会遇到问题。
In some links they mention about changing the locale of the browser to specific language. Is that necessary ?
仅当您显式测试时才需要确保该语言在浏览器区域设置为 fr 时正常工作
当然,我认为最好的做法是使用该语言打开基本网址。例如:http://example.com?lang=fr
关于java - 使用 WebDriver 自动化非英语网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22516207/