Re: [問題] webdriver無法選到element
你既然都用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
推
05/23 15:15,
5年前
, 1F
05/23 15:15, 1F
→
05/23 15:15,
5年前
, 2F
05/23 15:15, 2F
→
05/23 15:16,
5年前
, 3F
05/23 15:16, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):