Skip to content

Commit

Permalink
Corrected functioning with the deepl website (#88)
Browse files Browse the repository at this point in the history
* Corrected functioning with the deepl website

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added extra checks

* Switch to all_inner_texts which respects newlines

* Remove additional \n characters

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Monsterovich and pre-commit-ci[bot] authored Feb 2, 2023
1 parent 883169e commit ba05990
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions deepl/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,7 @@ async def __translate(self, script: str) -> str:
await page.wait_for_function(
"""
() => document.querySelector(
'textarea[dl-test=translator-target-input]').value !== ""
"""
)
await page.wait_for_function(
"""
() => !document.querySelector(
'textarea[dl-test=translator-target-input]').value.includes("[...]")
"""
)
await page.wait_for_function(
"""
() => document.querySelector("[dl-test='translator-source-input']") !== null
'd-textarea[dl-test=translator-target-input]')?.value?.length > 0
"""
)
except PlaywrightError as e:
Expand All @@ -139,8 +128,12 @@ async def __translate(self, script: str) -> str:
)

# Get information
input_textbox = page.get_by_role("textbox", name="Source text")
output_textbox = page.get_by_role("textbox", name="Translation results")
input_textbox = page.get_by_role("region", name="Source text").locator(
"d-textarea"
)
output_textbox = page.get_by_role(
"region", name="Translation results"
).locator("d-textarea")

self.translated_fr_lang = str(
await input_textbox.get_attribute("lang")
Expand All @@ -149,7 +142,9 @@ async def __translate(self, script: str) -> str:
await output_textbox.get_attribute("lang")
).split("-")[0]

res = str(await output_textbox.input_value())
res = str((await output_textbox.all_inner_texts())[0])
# the extra \n is generated by <p> tag because every line is covered by it
res = res.replace("\n\n", "\n")

await browser.close()

Expand Down

0 comments on commit ba05990

Please sign in to comment.