2017-07-05 127 views
-3
<div style="overflow:hidden;height:20px;" valign="middle"> 
<div id="IconImg_iconMenu_icon__dhtmlLib_274" class="imo" 
style="width:16px;height:16px;background- 
image:url('images/main/galleries/icon16x16gallery1b.png');background- 
position:0px -208px;margin-top:2px;cursor:pointer"></div> 

任何人都可以幫助我在Selenium中找到上述元素。試用不同的元素識別方法沒有任何幫助。無法識別硒中的元素

+1

您可以提供一些HTML樣本和您迄今爲止嘗試過的任何代碼嗎? –

+0

Html code is attached in my question .. driver.findElement(By.xpath(「div/* [(@ id ='IconImg_iconMenu_icon__dhtmlLib_274'(and(@class ='imo')]」))是我試過的方法 – AutomationTester

+0

只需嘗試driver.findElement(By.id(「IconImg_iconMenu_icon__dhtmlLib_274」)),否則請嘗試xpath // div [包含(@ id,'IconImg_iconMenu_icon__dhtmlLib_')] – Murthi

回答

0

有幾個可能的答案。 你可以找到xpathcssSelector

的Xpath: driver.findElement(By.xpath("//div[starts-with(@id, 'IconImg_iconMenu_icon'"));

CssSelector: driver.findElement(By.cssSelector("div[id^='IconImg_iconMenu_icon']"));

CssSelector^=裝置開始-用。