java中的Selenium无法识别classname

时间:2016-05-01 14:15:33

标签: java selenium

Selenium webdriver无法通过'classname'识别此元素,因为它有空格。我不能使用'name',因为它有多个具有相同名称的元素。

<span id="Fn14906146202366285507890WSRP:TransactionHistoryFG.OUTFORMATSelectBoxIt" tabindex="0" class="selectboxit dropdownexpandalbe selectboxit-btn" name="TransactionHistoryFG.OUTFORMAT" unselectable="on" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-owns="Fn14906146202366285507890WSRP:TransactionHistoryFG.OUTFORMATSelectBoxItOptions" aria-activedescendant="3" aria-label="Display Format" aria-live="assertive"><span id="Fn14906146202366285507890WSRP:TransactionHistoryFG.OUTFORMATSelectBoxItText" class="selectboxit-text" unselectable="on" data-val="2" style="max-width: 120px;">On Screen</span><span id="Fn14906146202366285507890WSRP:TransactionHistoryFG.OUTFORMATSelectBoxItArrowContainer" class="selectboxit-arrow-container" unselectable="on"><i id="Fn14906146202366285507890WSRP:TransactionHistoryFG.OUTFORMATSelectBoxItArrow" class="selectboxit-arrow selectboxit-default-arrow" unselectable="on"></i></span></span>

1 个答案:

答案 0 :(得分:1)

不要担心空格,您可以在CSS选择器中检查多个类:

driver.findElement(By.cssSelector(".selectboxit.dropdownexpandalbe.selectboxit-btn"))

或者,你也可以检查一个班级:

driver.findElement(By.cssSelector(".selectboxit"))
driver.findElement(By.className("selectboxit"))