作者rexyeah (ccccccc)
看板Python
標題Re: [問題] webdriver無法選到element
時間Tue May 21 22:35:02 2019
你既然都用chrome的devtool取到selector了
可以試試看在devtool的console tab下JS
假設你的selector是 #your_id > div
那麼就在console下document.querySelectorAll('#your_id > div');
看能不能找到element。如果可以那麼find_by_selector一定也可以找到
good luck!
EDIT:
應該是 find_elements_by_selector or find_element_by_selector
ref:
https://selenium-python.readthedocs.io/locating-elements.html
※ 引述《A601B8 (MBD)》之銘言:
: 標題: [問題] webdriver無法選到element
: 時間: Tue May 21 16:52:09 2019
:
: 先跟大家說聲抱歉,因為是公司的電腦沒辦法連上網路,所以只能用照相打馬賽克的方式
: 呈現
:
:
: 因為最近想要讓電腦自動化處理一些繁瑣的工作
: 最近學到可以用selenium取代
: 不過在定位下圖中的文字框時
: Xpath無法定位到
: 這個文字框也沒有 Id class 可供定位的名稱
: 也嘗試過用 find_by_tag_name(‘textarea’)
: 因為自己不太會寫css selector
: 嘗試了幾次也都失敗
:
: 不知道有沒有人可以幫我解決一下這個問題
:
:
: 網頁的樣子
: https://i.imgur.com/mooVKV4.jpg
: 從body向下看的位置
: https://i.imgur.com/dnkJa0S.jpg
: 文字框的原始碼
: https://i.imgur.com/toCZFXe.jpg
: Chrome提供的 xpath及selector
: https://i.imgur.com/fyteoBn.jpg
:
:
: 感謝各位的幫助
:
: --
: ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.74.132.95
: ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1558428731.A.246.html
: ※ 編輯: A601B8 (42.74.132.95), 05/21/2019 16:55:03
: 推 jn8029: 可能是JavaScript render出來的 05/21 19:41
: → jn8029: 喔 我剛沒注意到你已經是用selenium 請無視我上面的推文 05/21 19:42
: 推 uukoQAQ: find_element_by _css_selector(textarea) 05/21 20:53
: → uukoQAQ: 我晚點再幫你試試看,不確定 05/21 20:55
: 這個方法我今天好像有試過
: 印象中也是失敗
: 今天一直改一直改試了好多種都失敗QQ
: 推 rexyeah: devtool console下document.querySelectorAll(selector) 05/21 21:17
: → rexyeah: 看的到應該就可以找的到才對 05/21 21:18
:
: R大不好意思我有點看不太懂你的回覆
: 是指我要import devtool console
: 然後用document.querySelectorAll這個功能嗎?
: ※ 編輯: A601B8 (42.74.132.95), 05/21/2019 21:35:30
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.161.240.73
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1558449305.A.203.html
※ 編輯: rexyeah (1.161.240.73), 05/21/2019 22:37:49
推 wsybu: 抓element 之前有用WebDriverWait?有可能那個元件是延遲被 05/23 15:15
→ wsybu: js產生出來的 05/23 15:15
→ wsybu: 抱歉推錯文...應該要推原po 05/23 15:16