我正在使用Selenium來使用Java語言自動化UI。Selenium(Java):將鼠標懸停在某個按鈕上,然後單擊其中一個選項
我有一個動作按鈕,當用戶將鼠標懸停接管行動按鈕鼠標,它給出了兩個可單擊選項 - 創建和編輯
我已存儲的CSS定位器作爲枚舉了動作按鈕,也爲創建和編輯(可點擊)鏈接分別爲ACTIONBUTTON,CREATEACTION,EDITACTION。
我使用的Java代碼像下面,但它給出了一個錯誤說java.lang.ClassCastException:org.openqa.selenium.By $ ByCssSelector不能轉換到org.openqa.selenium.WebElement
Actions actions = new Actions(driver);
actions.moveToElement((WebElement) DCSAdminEnums.ACTIONBUTTON.getLocator());
actions.moveToElement((WebElement) DCSAdminEnums.CREATEACTION.getLocator());
actions.click();
actions.perform();
請建議您使用我擁有的Enums來幫助更好地處理此問題。
更新: 我也試圖與代碼下面的風格,但它沒有工作:-(
WebElement menu = driver.findElement((By.xpath("//*[@id='button-1177-btnInnerEl']")));
WebElement submenu = driver.findElement((By.cssSelector("a[id='menuitem-1175-itemEl']")));
Actions action = new Actions(driver);
action.moveToElement(menu).perform();
Thread.sleep(2000);
action.click(submenu).perform();
'findElement' ** – sircapsalot
謝謝,但對我來說沒有工作:-( 我甚至試着寫下面的風格(不使用枚舉),但仍然沒有運氣.. WebElement菜單= driver.findElement ((By.xpath(「// * [@ id ='button-1177-btnInnerEl']」))); WebElement submenu = driver.findElement((By.cssSelector(「a [id ='menuitem-1175- ();); action.click(submenu).perform();); –
對不起,我的模糊迴應,我想我是無法識別確切的CSS/XPATH定位器和/或子菜單項對Selenium不可見。但正如你所說,它是一個不同的問題。 再次感謝:-) –