【问题标题】:Python Selenium Can't locate google sheet element [closed]Python Selenium找不到谷歌工作表元素[关闭]
【发布时间】:2020-08-22 07:19:49
【问题描述】:

我已经尝试了所有可能的方法来从谷歌表格中找到下面的导入文件窗口元素,但还没有找到它。代码如下:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

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

import time

import pynput

from pynput.keyboard import Key, Controller
keyboard = Controller()

import os
import logging
import glob

#save chrome user data to chromedriver
options = webdriver.ChromeOptions() 
options.add_argument("") #Path to your chrome profile

driver = webdriver.Chrome(executable_path="C:\\Program Files (x86)\\chromedriver.exe", chrome_options=options)

#open the google sheet in chrome
driver.get("https://docs.google.com/spreadsheets/d/")
wait3 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "docs-file-menu")))

#click on file menue
wait3 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "docs-file-menu")))
driver.find_element_by_id("docs-file-menu").click()

#click on import
wait3 = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, ":4q")))
driver.find_element_by_id(":4q").click()

Google Sheet import Window

【问题讨论】:

  • 欢迎来到 SO。发帖stackoverflow.com/help/mcve 获取帮助
  • 请分享您到目前为止编写的任何代码。以便我们进行调查并提出更正建议。
  • 试图对窗口中的所有元素使用所有选项(ID、类、Xpaths、Css 选择器)。

标签: python selenium google-sheets


【解决方案1】:

您要查找的元素在iframe 中。

首先,您必须切换到 iframe,然后开始搜索您的元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-30
    • 2021-12-17
    • 2018-11-07
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多