2016-06-10 3 views
0

나는 www.bigbasket.com의 검색 결과에 대한 툴팁 텍스트를 얻으려고하고 아래 코드Selenium WebDriver를 사용하여 툴팁 텍스트를 얻는 방법은 무엇입니까?

@FindAll({@FindBy(xpath="//*[contains(@id,'product')][not(contains(@style,'display:none'))]/div/span[2]/a")}) 
    List<WebElement> lblProductName; 

public String verifySearchResults(WebDriver browser, String productName){ 
     System.out.println(lblProductName.size()); 
     try{ 
      Actions actions = new Actions(browser); 
      for(WebElement eachElement:lblProductName){ 
       System.out.println(eachElement.getAttribute("href")); 
       actions.moveToElement(eachElement).perform(); 
       //Actions action = new Actions(driver); 
       actions.moveToElement(eachElement).build().perform(); 
       WebElement toolTipElement = browser.findElement(By.cssSelector(".uiv2-tool-tip-hover ")); 
       System.out.println("Tooltip text is "+toolTipElement.getAttribute("textContent")); 
      } 
     }catch(Exception e){ 
      System.out.println(e.getMessage()); 
     } 
     return productName; 
    } 

을 사용했다 그러나 위의 코드와 난 단지 도구 설명 텍스트를 얻을 수 있어요 첫 번째 검색 결과 모든 검색 결과의 도구 설명 텍스트를 가져 오는 방법을 알려주십시오. 1.을 따르지

수동 단계는 2. 클릭하여 도구 설명 텍스트

+0

actions.moveToElement (각 요소) .perform(); // Actions action = new Actions (driver);'쓸모없는 것 같습니다. 거기에 오타가 있습니까? – nullpointer

+0

지금까지 얻은 결과를 공유하십시오. 실제로 기대하고 계신 것 같습니다. – nullpointer

답변

0
를 생략하고 검색 결과의 각을 통해 버튼을 3. 검색 애플 4. 마우스를 살펴보기 www.bigbasket.com하기

WebElement toolTipElement = browser.findElement(By.cssSelector(".uiv2-tool-tip-hover ")); //this shall always access the same element 

대신 당신은

로 사용하여야 하나 : 나는 관찰 할 수

한 것은 당신이 사용하는 여러 tool-tip-hover 요소가있다

또는

내가 부모를 작성 제안 및 더 하위에 접근 (그에 따라 코드 흐름에 넣을 수) :

WebElement parentImgTitle = driver.findElements(By.cssSelector(".uiv2-list-box-img-title"); 
WebElement childTooltip = parentImgTitle.findElement(By.cssSelector(".uiv2-tool-tip-hover ")); 

을 : 또한 나는 확실하지 않다 당신의 행동이 여기서 어떤 역할을 할 것인가. 나는 공중 선회 이상의 세부 사항을 얻을 존재가 의심. 한번 무시하고 무시하십시오.