-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Description
The code as is did not work for me, I made a few tweaks, I commented out TranslateButton, this was no longer needed, as it detects words and automatically translates. I also changed the OutputElement path. Overall, great tutorial, and this method still works!
Code changes:
driver = webdriver.Firefox()
driver.get(f"https://translate.google.com/#{source_language}/{destination_language}/")
TranslateElement = "//input[@id='gt-submit']"
InputElement = "//textarea[@id='source']"
# OutputElement = "//div[@id='gt-res-dir-ctr']"
OutputElement = "//span[@class='tlid-translation translation']"
# TranslateButton = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(TranslateElement))
InputBox = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(InputElement))
InputBox.send_keys(toBeTranslated)
# TranslateButton.click()
sleep(3)
ResultElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(OutputElement))
# import pdb; pdb.set_trace()
print(f"#### Result <{source_language}> -> <{destination_language}>")
print(ResultElement.text)
print("####")
driver.quit()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels