We are currently working on a Japanese web application and are experimenting with a unique method to convert Japanese labels into English. Here is the approach we are using (though unsure if it's correct):
Approach (using Selenium):
- Open the webpage.
Retrieve labels as we navigate through the webpage.
Send each label to an API (Japanese dictionary) for translation to English.
Set back the translated English word to the label using JavaScript executor.
I have successfully obtained the translated English words for the Japanese labels, but I am facing issues in setting them back on the webpage. Below is the piece of Selenium code attempting to achieve this:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.onload=function(){document.getElementById('expiry').textContent='Expiration Date';}");
Although there are no error messages in the Eclipse console, I cannot observe the English text on the page.
HTML
<html>
<body>
<table class="imui-form" style="width:1050px;">
<div class="imui-chapter-title" style="width:1050px;">
<h2>取引先情報</h2>
</div>
<tr>
<th style="width:80px;" >
<label id="expiry">有効期限</label>
</th>
<td style="width:220px;">
<input type="text" placeholder="" value="2016/08/09" name="fromdate" id="fromdate" maxlength="" style="width:100px; height:15px;">
<img src="./imart/images/calendar_btn.png" />
~
<input type="text" placeholder="" value="" name="todate" id="todate" maxlength="" style="width:100px; height:15px;">
<img src="./imart/images/calendar_btn.png" />
</td>
</table>
</body>
</html>
In light of this, I have two questions:
- Can someone advise me on whether my current approach is viable or suggest a better alternative?
- How can I ensure that the above JavaScript works correctly using Selenium?