2015-05-08 21 views
1

我正在使用Selenium Webdriver和Python。在一個網頁,我有一個輸入的複選框:爲什麼硒webdriver認識到<ins>而不是輸入框本身?

<input class=「theme1" type="checkbox" value="1" name=「sale_enabled"> 
<ins class=「theme-helper" style="position: absolute; top: 0%; left: 0%; display: block; border: 0px none; opacity: 0;"/> 

當我這樣做:

driver.find_element_by_name(‘sale_enabled’).click() 

硒的webdriver找不到該複選框,並檢查它。

,但如果我這樣做:

driver.find_element_by_class(‘theme1-helper’).click() 

然後硒能找到它。

這是爲什麼?

+0

看起來像你缺少你輸入元素上關閉標籤。這可能與它有關。 – jzarob

+0

你可以有'theme1'或'theme-helper'類。在第二行代碼中,類名稱與html不匹配。 – Amey

+0

@jzarob輸入元素不需要關閉標籤。看起來像在class =後面的輸入標記中有一個ascii引用,請將其更改爲常規引用。 –

回答

2

你的硒選擇器看起來是正確的(儘管你的html中不存在類theme1-helper)。

看起來像你的問題可能是你的HTML使用一個奇怪的字符,導致它解析不正確。

<input class=「theme1" type="checkbox" value="1" name=「sale_enabled"> 
      ^this character should be "   ^and so should this one 
<ins class=「theme-helper" style="position: absolute; top: 0%; left: 0%; display: block; border: 0px none; opacity: 0;"/> 

所以,貌似有些問題與屬性的名稱不是結果訪問:

<input class="theme1" type="checkbox" value="1" name="sale_enabled"> 
<ins class=「theme-helper" style="position: absolute; top: 0%; left: 0%; display: block; border: 0px none; opacity: 0;"/> 
相關問題