亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Python 中使用 selenium 單擊文本框并輸入文本?

如何在 Python 中使用 selenium 單擊文本框并輸入文本?

Go
阿晨1998 2022-10-11 10:07:00
我正在嘗試使用 Selenium 輸入登錄頁面以轉到該頁面并單擊登錄框并輸入一些文本。我的代碼允許我進入登錄頁面,單擊登錄框,這是我的代碼中斷的部分。代碼from selenium import webdriveroptions = webdriver.ChromeOptions()options.add_argument('--ignore-certificate-errors')options.add_argument("--test-type")driver = webdriver.Chrome(executable_path = r'C:\Users\user\Downloads\chromedriver_win32\chromedriver.exe')driver.get("https://accounts.google.com/signin/v2/identifier?passive=1209600&continue=https%3A%2F%2Fdocs.google.com%2F&followup=https%3A%2F%2Fdocs.google.com%2F&emr=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin")text_area= driver.find_element_by_xpath('//*[@id="view_container"]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[1]/div/div[2]')text_area.click()text_area.send_keys(email_address)代碼打開頁面,如果有人想知道或者這可能是什么影響我的代碼是登錄頁面,當您使用訪客帳戶訪問 Google 文檔時,單擊登錄文本框,并且無法輸入任何文本. 在代碼應該輸入文本的時間點,我收到此錯誤。錯誤Traceback (most recent call last):  File "file.py", line 8, in <module>    text_area.click()  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click    self._execute(Command.CLICK_ELEMENT)  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute    return self._parent.execute(command, params)  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute    self.error_handler.check_response(response)  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response    raise exception_class(message, screen, stacktrace)誠然,這有點超出我的想象,我想知道是否有人知道如何解決這個錯誤,以及他們是如何找到解決方法的,因為我接下來的合理步驟是輸入密碼,選擇新文檔,并在 Google Doc 中輸入文本。
查看完整描述

2 回答

?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

您應該嘗試在輸入中設置值,但您當前的代碼正在獲取div元素,而輸入框正在攔截對 div 元素的點擊。相反,請嘗試使用下面的代碼行。

text_area= driver.find_element_by_xpath("//input[@name='identifier']")


查看完整回答
反對 回復 2022-10-11
?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

您可以使用waits,即:

from selenium import webdriver

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.common.keys import Keys


driver = webdriver.Chrome(executable_path="C:\Users\user\Downloads\chromedriver_win32\chromedriver.exe")

driver.maximize_window()

driver.get("https://accounts.google.com/signin/v2/identifier?passive=1209600&continue=https%3A%2F%2Fdocs.google.com%2F&followup=https%3A%2F%2Fdocs.google.com%2F&emr=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin")

wait = WebDriverWait(driver, 10)


# usr

el = wait.until(EC.visibility_of_element_located((By.ID, "identifierId")))

el.send_keys("[email protected]")

el.send_keys(Keys.ENTER)


# pwd

el = wait.until(EC.visibility_of_element_located((By.XPATH, "//input[@type='password']")))

el.send_keys("XXXXX")

el.send_keys(Keys.ENTER)


# you're logged


查看完整回答
反對 回復 2022-10-11
  • 2 回答
  • 0 關注
  • 355 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號