惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
小众软件
小众软件
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
博客园_首页
G
Google Developers Blog

博客园 - cutepig

換博客了,新地址https://cutepig123.github.io/ 光盘是个好东西 俺买过的电子产品 抽象的好与坏 垂直方向的努力更有意义 python GUI test tool AirtestIDE_2019-04-16_py3_win64 冯唐论加班 Prometheus 文件系统api为何可以这么简洁以及我們這個抓圖模塊的設計難點 好繫統是一次性設計出來的嗎 jaeger tracing CS lessons c++ 书籍 my codes 我写的代码 写了一个自动用google翻译文档的工具 用几种语言实现socks server 一個不錯的Modern CMake的入門教程 Modern CMake remote ssh for vscode test
google translate automation using selenium
cutepig · 2021-02-15 · via 博客园 - cutepig
import os, sys, requests
from selenium import webdriver

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time


def translate(browser):
    wait = WebDriverWait(browser, 10)  # 等待加载10s

    url = 'https://translate.google.com.hk/?hl=en&tab=rT&sl=en&tl=zh-CN&op=translate'
    browser.get(url)

    input = wait.until(EC.presence_of_element_located(
        (By.XPATH, '/html/body/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[1]/span/span/div/textarea')))
    time.sleep(3)
    input.send_keys('hello world')

    output = wait.until(EC.presence_of_element_located(
        (By.XPATH, '/html/body/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]')))
    time.sleep(3)
    print(output)
    print(output.get_attribute("innerText"))
    

if 1:
    # Not work
    #chrome_options = webdriver.ChromeOptions()
    #chrome_options.add_argument("--disable-popup-blocking")

    #browser = webdriver.Chrome(options=chrome_options)
    browser = webdriver.Chrome()

    browser.maximize_window()  # 最大化窗口
    wait = WebDriverWait(browser, 10)  # 等待加载10s

    # txtTemp, btnSubmit
    translate(browser)

# pass!
if 0:
    driver = webdriver.Chrome()
    driver.get("http://www.python.org")
    assert "Python" in driver.title
    elem = driver.find_element_by_name("q")
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    print (driver.page_source)