0

我想爲我的WebApp選擇菜單選項,能夠點擊菜單,菜單選項也可見但不能點擊菜單選項。無法點擊硒從菜單選項

如果我嘗試檢查菜單選項的可見性,那麼從Selenium API中可以看出它不可見,但實際上它已經可以在屏幕上看到。

是否有使用Selenium IE Driver選擇菜單和菜單選項的標準。

以下是菜單/菜單選項的代碼:

<DIV style="BORDER-BOTTOM: 2px outset; POSITION: absolute; BORDER-LEFT: 2px outset; WIDTH: 162px; FONT-FAMILY: Tahoma; BACKGROUND: #e4e4e4; HEIGHT: 106px; FONT-SIZE: 8pt; BORDER-TOP: 2px outset; TOP: 0px; BORDER-RIGHT: 2px outset; LEFT: 0px"> 
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 15px; PADDING-RIGHT: 2px; HEIGHT: 17px; COLOR: black; CURSOR: hand; PADDING-TOP: 2px" onmouseover="this.style.background='darkblue';this.style.color='white';" onmouseout="this.style.background=this.runtimeStyle.background;this.style.color='black';" onclick="parent.smConfig_Click(0,'smConfig0')"><SPAN>Config. Management</SPAN> </DIV><INPUT id=lgx_smConfig01 type=hidden SP="" LP="<LinkParams lgx_ID='WideDetail' FromDate='@Data.DefaultDate.FromDate~' ToDate='@Data.DefaultDate.ToDate~' lgx_DetailID='dtlConfig' FirstTime='1' ConfigType='2' />" Modal="" Features="" Target="_top" Action="lgx_Frame.aspx"> 
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 15px; PADDING-RIGHT: 2px; HEIGHT: 17px; COLOR: black; CURSOR: hand; PADDING-TOP: 2px" onmouseover="this.style.background='darkblue';this.style.color='white';" onmouseout="this.style.background=this.runtimeStyle.background;this.style.color='black';" onclick="parent.smConfig_Click(1,'smConfig1')"><SPAN>Custom Configuration</SPAN> </DIV><INPUT id=lgx_smConfig11 type=hidden SP="" LP="<LinkParams lgx_ID='Default' lgx_ListID='lstCustomConfig' ConfigType='1' />" Modal="" Features="" Target="_top" Action="lgx_Frame.aspx"> 
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 15px; PADDING-RIGHT: 2px; HEIGHT: 17px; COLOR: black; CURSOR: hand; PADDING-TOP: 2px" onmouseover="this.style.background='darkblue';this.style.color='white';" onmouseout="this.style.background=this.runtimeStyle.background;this.style.color='black';" onclick="parent.smConfig_Click(2,'smConfig2')"><SPAN>Custom Transition</SPAN> </DIV><INPUT id=lgx_smConfig21 type=hidden SP="" LP="<LinkParams lgx_ID='Default' lgx_ListID='lstCustomTransition' Flag='512' Title='Custom' />" Modal="" Features="" Target="_top" Action="lgx_Frame.aspx"> 
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 15px; PADDING-RIGHT: 2px; HEIGHT: 17px; COLOR: black; CURSOR: hand; PADDING-TOP: 2px" onmouseover="this.style.background='darkblue';this.style.color='white';" onmouseout="this.style.background=this.runtimeStyle.background;this.style.color='black';" onclick="parent.smConfig_Click(3,'smConfig3')"><SPAN>Person Hierarchy Level</SPAN> </DIV><INPUT id=lgx_smConfig31 type=hidden SP="" LP="<LinkParams lgx_ID='Default' lgx_ListID='lstPersonLevel' />" Modal="" Features="" Target="_top" Action="lgx_Frame.aspx"> 
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 15px; PADDING-RIGHT: 2px; HEIGHT: 17px; COLOR: black; CURSOR: hand; PADDING-TOP: 2px" onmouseover="this.style.background='darkblue';this.style.color='white';" onmouseout="this.style.background=this.runtimeStyle.background;this.style.color='black';" onclick="parent.smConfig_Click(4,'smConfig4')"><SPAN>Role</SPAN> </DIV><INPUT id=lgx_smConfig41 type=hidden SP="" LP="<LinkParams lgx_ID='Default' lgx_ListID='lstRoleConfig' />" Modal="" Features="" Target="_top" Action="lgx_Frame.aspx"> 
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 15px; PADDING-RIGHT: 2px; HEIGHT: 17px; COLOR: black; CURSOR: hand; PADDING-TOP: 2px" onmouseover="this.style.background='darkblue';this.style.color='white';" onmouseout="this.style.background=this.runtimeStyle.background;this.style.color='black';" onclick="parent.smConfig_Click(5,'smConfig5')"><SPAN>Status</SPAN> </DIV><INPUT id=lgx_smConfig51 type=hidden SP="" LP="<LinkParams lgx_ID='Default' lgx_ListID='lstStatusTy' />" Modal="" Features="" Target="_top" Action="lgx_Frame.aspx"> </DIV></DIV> 

在上面的代碼菜單選項,我需要點擊角色選項。 這個選項是可見的點擊配置菜單,但點擊任何這樣的菜單選項都沒有發生,它也沒有拋出任何異常。

請讓我知道您的意見或建議,以解決此問題。

謝謝。

試過代碼1:

WebElement configMenu = driver.findElement(By.id("mConfigLabel")); 
configMenu.click(); 
WebElement menuOption = driver.findElement(By.xpath("//div[@id='oMenuCntxtsmConfig']/div/div[4]")); 
menuOption.click(); 

試過代碼2:

WebElement configMenu = driver.findElement(By.id("mConfigLabel")); 
configMenu.click(); 
WebElement menuOption = driver.findElement(By.xpath("//div/descendant:span[contains(text(),'Role']")); 
menuOption.click(); 

試過代碼3:

configMenu.click(); 
Actions builder = new Actions(driver); 
WebElement roleMenuOption = driver.findElement(By.xpath("//div[@id='oMenuCntxtsmConfig']/div/div[4]")); 
builder.moveToElement(configMenu).click(roleMenuOption).build().perform(); 

試過代碼4:

WebElement configMenu = driver.findElement(By.id("mConfigLabel")); 
configMenu.click(); 
WebElement roleMenuOption = driver.findElement(By.xpath("//div[@id='oMenuCntxtsmConfig']/div/div[4]")); 
((JavascriptExecutor) driver).executeScript("arguments[0].click();", roleMenuOption); 
+0

您正在嘗試的代碼是什麼?您可以在此粘貼嗎? –

+0

@Abhi_Mishra感謝ABHI的答覆,我已經把我做過嘗試,但並沒有解決問題的四個採樣代碼。 – SmartSolution

回答

0

根據我對你的問題的理解,你只需點擊該部門。

您的html代碼表示onclick事件與div關聯。 此onClick事件可能會使您的輸入(最初隱藏給出)可見。

現在你也需要點擊這個輸入

例如,對於點擊角色選項,你需要追加這一行

driver.findElementByID("lgx_smConfig41").click(); 

希望這可以幫助你。

+0

感謝您的回覆,讓我試試,我會盡快給您更新。 – SmartSolution

+0

我試圖與該但它將引發ElementNotVisibleException,所以我嘗試使用JavascriptExecutor: ((JavascriptExecutor)驅動程序).executeScript( 「參數[0]。點擊();」,元素); 但沒有運氣:( – SmartSolution

0

玩下拉菜單使用硒是棘手的,因爲下拉/菜單項是隱藏的,直到用戶點擊下拉菜單時才顯示。

你的方法有點不對。

右鍵您正在訪問的下拉/菜單

錯誤您正在訪問的下拉/菜單裏面的物品的方式,因爲他們不能直接訪問被隱藏在菜單的方式/下拉列表。

請參閱下面的代碼正確地訪問特定的菜單項,

WebElement DropdownList = driver.findElement(By.id("mConfigLabel")); 
Select clickThis = new Select(DropdownList); 
clickThis.selectByValue("Role"); 

我假設你的男人的ID /下拉是「mConfigLabel」

上有不同的代碼口味用於訪問菜單項目的stackover流程...請確認一下。

希望這會有所幫助....一切順利:)