selenium python的md-option,大部分时间都失败了

时间:2017-03-16 12:38:51

标签: python selenium dropdown

您好我有以下代码

<md-option ng-repeat="sector in allSector | orderBy:'name'" ng-value="{"id":239,"name":"MU-BHND-JC32-0033","regionInventory":{"id":18,"regionName":"Mumbai","zone":{"id":4,"name":"WEST","longitude":73.1812,"country":{"id":3,"name":"INDIA","countryCode":"IND"},"latitude":22.3072},"stateCode":"MU","latitute":19.076,"longitude":72.8777},"latitute":19.29117616,"longitude":73.04375901,"coordinates":null,"centroid":null}" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_982" aria-checked="true" value="[object Object]" style>

基本上我想从上面的代码中选择元素MU-BHND-JC32-0033然后点击它。

随着身份不断变化,我不愿意去找id。

如果有人可以帮我点击使用xpath和ng-value。

我尝试了以下但是失败了

subRegOpt = driver.find_element_by_xpath("//md-option[@ng-value='MU-BHND-JC32-0033']")
sleep(5)
subRegOpt.click() 

1 个答案:

答案 0 :(得分:0)

尝试替换

subRegOpt = driver.find_element_by_xpath("//md-option[@ng-value='MU-BHND-JC32-0033']")

subRegOpt = driver.find_element_by_xpath("//md-option[contains(@ng-value, 'MU-BHND-JC32-0033')]")