簡體   English   中英

Java中的Selenium無法識別類名

[英]Selenium in java unable to identify classname

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>

不用擔心空格,您可以在CSS選擇器中檢查多個類:

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

或者,您也可以只檢查一個班級:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM