2017-01-15 1 views
0

메인 메뉴 위로 마우스를 가져 가서 자바 셀렌을 사용하여 하위 메뉴를 선택하려고합니다. 메뉴 위로 마우스를 올려 놓았지만 하위 메뉴를 선택할 수 없습니다. linktext에 의해 나는 항상 xpath를 사용하면 성공적으로 빌드가되지만 새로운 페이지를 열지 않는다는 "존재하지 않는다"라는 에러를 얻는다. 지금까지 내 코드는 여기메뉴 위로 마우스를 가져 가서 자바 셀렌의 하위 메뉴를 선택하십시오.

System.setProperty("webdriver.chrome.driver","C:/Driver/chromedriver.exe");  
    WebDriver webDriver = new ChromeDriver();  
    webDriver.manage().window().maximize(); 
    webDriver.navigate().to("https://www.skiutah.com"); 

    String NavTo = "DEALS"; 
    String pathx = "//*[@id=\"top_menu\"]/ul/li[4]/ul/li[1]/ul/li[2]/a" ; 
    WebElement element = webDriver.findElement(By.linkText(NavTo)); 
    WebElement el = webDriver.findElement(By.xpath(pathx)); 
    Actions action = new Actions(webDriver); 
    action.moveToElement(element).perform(); 
    action.moveToElement(el).click(); 

답변

0

나는 호버링하고 하위 메뉴를 클릭하는 방식이 올바르지 않다고 생각한다.

html을 공유하지 않았으므로 내가 찾은 요소를 확인하는 것이 지루할 정도로 정확하지 않습니다.

다음

build() 방법을 사용하는 단일 단계로 모든 작업 목록을 컴파일 할 준비가

을 수행 할 -이 :

WebElement menu = driver.findElement(By.your_locator); 
WebElement sub_menu = driver.findElement(By.your_locator); 
Actions action = new Actions(driver); 
action.moveToElement(menu).moveToElement(sub_menu).click().build().perform(); 

Explaination을 - 모든 좋은 경우, 다음 코드를 시도하는 당신에게 도움이 될 수 있습니다

1

WebDriver에서 우리는 Mouse 이벤트를 제어 할 수있는 옵션을 제공합니다. 이 코드를 사용해보십시오. 이것은 목적을 달성해야합니다.

driver.get("https://www.skiutah.com/"); 
WebElement deals = driver.findElement(By.xpath("//a[@title='Deals']")); 
Mouse mouse = ((HasInputDevices) driver).getMouse(); 
Locatable hoverItem = (Locatable) deals; 
mouse.mouseMove(hoverItem.getCoordinates()); 
WebElement beginner = driver.findElement(By.xpath("//a[text()='Beginner']")); 
new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOf(beginner)); 
Locatable clickItem = (Locatable) beginner; 
mouse.mouseDown(clickItem.getCoordinates()); 
mouse.mouseUp(clickItem.getCoordinates()); 
System.out.println(driver.getTitle()); 
1

마우스 오버 액션을 사용하려면 build.perform을 사용해야합니다. 그것은 행동 연계 (action chaining)라고 불리며, 결국 행동을 함께 수행합니다. 또는 아래와 같이 줄을 바꾸면됩니다. 나는보기 좋게 보았다.

String NavTo = "DEALS"; 
String pathx = "//*[@id=\"top_menu\"]/ul/li[4]/ul/li[1]/ul/li[2]/a" ; 
WebElement element = webDriver.findElement(By.linkText(NavTo)); 
WebElement el = webDriver.findElement(By.xpath(pathx)); 
Actions action = new Actions(webDriver); 
action.moveToElement(el).click(); 
String NavTo = "DEALS"; 
String pathx = "//*[@id=\"top_menu\"]/ul/li[4]/ul/li[1]/ul/li[2]/a" ; 
WebElement element = webDriver.findElement(By.linkText(NavTo)); 
WebElement el = webDriver.findElement(By.xpath(pathx)); 
Actions action = new Actions(webDriver); 
action.moveToElement(el).click(); 
action.moveToElement(element).perform(); 
0
//locate the menu to hover over using its xpath 
WebElement menu = driver.findElement(By.linkText("Deals")); 
//Initiate mouse action using Actions class 
Actions builder = new Actions(driver); 
// move the mouse to the earlier identified menu option 
builder.moveToElement(menu).build().perform(); 
// wait for max of 5 seconds before proceeding. 
// until this submenu is found 
WebDriverWait wait = new WebDriverWait(driver, 5); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"top_menu\"]/ul/li[4]/ul/li[1]/ul/li[2]/a"))); 
//identify menu option from the resulting menu display and click 
WebElement menuOption = driver.findElement(By.xpath("//*[@id=\"top_menu\"]/ul/li[4]/ul/li[1]/ul/li[2]/a")); 
menuOption.click(); 
주 메뉴로
0
This works for me first time, but if repeated for other menu item then it cant find or something. 

WebElement menu = driver.findElement(By.your_locator); 
WebElement sub_menu = driver.findElement(By.your_locator); 
Actions action = new Actions(driver); 
action.moveToElement(menu).moveToElement(sub_menu).click().build().perform(); 
0

먼저 Mousehover 한 다음 하위 메뉴 중 하나를 클릭합니다.

WebDriverWait Wait = new WebDriverWait(driver,10); 
Wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//[@id='top_menu']/ul/li[4]/a")))); 
Actions mousehover = new Actions(driver); 
mousehover.moveToElement(driver.findElement(By.linkText("Deals"))).build().perform(); 
Wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.linkText("All Deals")))); 
driver.findElement(By.linkText("All Deals")).click(); 
0

하위 메뉴를 '클릭'하려고합니다. 기본 메뉴로 마우스를 이동해야하며 하위 메뉴를로드하는 데 몇 초가 걸립니다. 그럼 내가 하위 메뉴를 찾아 그것을 클릭해야합니다. 다음은 내가

Actions ac = new Actions(dr); 
WebElement we = dr.findElement(By.xpath(".//*[@id='ddtopmenubar']/ul/li[1]/a")); 
ac.moveToElement(we).build().perform(); 
WebDriverWait wait = new WebDriverWait(dr, 5); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='dataingestionsubmenu']/li[2]/a"))); 
WebElement e= dr.findElement(By.xpath(".//*[@id='dataingestionsubmenu']/li[2]/a")); 
e.click(); 

를 사용하는 코드이지만 밖으로 작동하는 것 같다하지 않습니다.

점점 예외로 : org.openqa.selenium.WebDriverException : performActions이 정보를 구축 : 버전 : '알 수없는'수정 '알 수없는'시간 '알 수없는'

내가 디버그에서 동일한 작업을 수행 할 때 모드를 선택하면 하위 메뉴를 클릭 할 수 있습니다.

+0

도이 코드를 시도 : WebElement menu = driver.findElement (By.your_locator); WebElement sub_menu = driver.findElement (By.your_locator); 작업 action = new 작업 (드라이버); action.moveToElement (menu) .moveToElement (sub_menu) .click(). build(). perform(); –

관련 문제