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

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

選擇 xpath - Selenium

選擇 xpath - Selenium

狐的傳說 2022-07-26 20:51:18
我正在用硒編寫一個用于火種的機器人,但它不起作用。這是我的代碼。fb_button =  self.driver.find_element_by_xpath('//*[@id="content"]/div/div[1]/div/div/main/div/div[2]/div[2]/div/div/span/div[2]/button')fb_button.click()此代碼用于單擊 facebook 登錄按鈕。但是,當我運行代碼時,它運行不正常。我收到這樣的錯誤。raise exception_class(message, screen, stacktrace)selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="content"]/div/div[1]/div/div/main/div/div[2]/div[2]/div/div/span/div[2]/button"}但是,當我嘗試創建一個對象并嘗試調用此函數時,它會返回一些內容。按鈕的 HTML:<button type="button" class="button Lts($ls-s) Z(0) CenterAlign Mx(a) Cur(p) Tt(u) Bdrs(100px) Px(24px) Px(20px)--s Py(0) Mih(42px)--s Mih(50px)--ml button--outline Bdw(2px) Bds(s) Trsdu($fast) Bdc(#fff) C(#fff) Bdc(#fff):h C(#fff):h Bdc(#fff):f C(#fff):f Bdc(#fff):a C(#fff):a Fw($semibold) focus-button-style W(100%) Fz(4vw)--ms" draggable="false" aria-label="Facebook ile oturum a?"><span class="Pos(r) Z(1) D(ib)">Facebook ile oturum a?</span></button>
查看完整描述

2 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

你可以等到元素可以點擊并出現在 HTML dom 中。


from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.support.ui import WebDriverWait


fb_button = WebDriverWait(driver, 10).until(

            EC.element_to_be_clickable((By.XPATH, "your_xpath")))

fb_button.click()


查看完整回答
反對 回復 2022-07-26
?
胡說叔叔

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

您可以使用 xpath 單擊元素:


WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Facebook ile oturum a?']"))).click()

注意:您必須添加以下導入:


from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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