2013-09-27 1 views
1

셀레늄 및 CSS/XPATH 로케이터의 새로운 기능입니다. CSS가 작동하지만 이에 상응하는 XPath가없는 문제를 발견했을 때 정말 이유를 알고 싶습니다. 예제에서 Scala를 사용하고 있지만 여전히 일반적인 Java Selenium2 라이브러리입니다. 나는 또한 FirefoxDrivercss와 셀렌의 해당 xpath 사이의 차이점 2.0

가 여기에 HTML의 흥미로운 부분 사용 : 나는 나를 위해 작동

val filter = driver.findElement(By.cssSelector("li.k-filter-item")) 

으로 납니다

... 
<li class="k-item k-filter-item k-state-default k-last" role="menuitem" style="z-index: auto;"> 
    ... 
    <form class="k-filter-menu k-secondary"> 
    <div> 
     <div class="k-filter-help-text">Show items with value that:</div> 
     <span class="k-widget k-dropdown k-header" style="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="" aria-disabled="false" aria-readonly="false" aria-busy="false"> 
     <span class="k-widget k-datetimepicker k-header" style=""> 
     <div> 
     <button class="k-button" type="submit">Filter</button> 
     <button class="k-button" type="reset">Clear</button> 
     </div> 
    </div> 
    </form> 
</li> 
... 

.

그런 다음 버튼을 찾고 싶습니다. 그것은 동적 메뉴가 없습니다 미끄러 져 어떤 말았 어, 그래서 나는 그것이 나타날 때까지 기다릴 필요가 :

new WebDriverWait(driver, selectorTimeout).until(
    new ExpectedCondition[Boolean] { 
    override def apply(d: WebDriver) = { 
     filter.findElement(By.cssSelector("button[type=submit]")).isDisplayed 
    } 
    }) 

을 그리고도 잘 작동합니다. 제 질문은 xpath가 왜 작동하지 않는 것입니까?

new WebDriverWait(driver, selectorTimeout).until(
    new ExpectedCondition[Boolean] { 
    override def apply(d: WebDriver) = { 
     filter.findElement(By.xpath("//button[@type='submit']")).isDisplayed 
    } 
    }) 

아무도 없습니까?

[편집]
셀레늄 버전 : 2.35.0
파이어 폭스 드라이버 : 2.35.0

지금은 오페라와 함께 노력할 것입니다. 그것은 현재 요소의 자손/아이 검색 할 수 있습니다 있도록

+0

오류가 발생 했습니까? '// button [contains (@ type, 'submit')]'시도해 주시겠습니까? –

+0

와우. FF보다 다른 브라우저에서 사용해 보셨습니까? 이것은 확실히 작동해야합니다. CSS 선택기를 사용하는 것이 더 낫지 만 혼란 스러움을 이해합니다. 이것은 나도 당황하게한다. Selenium 버전은 무엇입니까? 그리고 어떤 파이어 폭스? 파이어 폭스에서는 CSS 선택기와 XPath를 모두 지원해야합니다. 허. –

+0

XPath 앞에'.'가 있어야합니다.'.// button [@ type = 'submit']'. 또한 좀 더 정교한 방법을 시도해보십시오 :'.// descendant :: button [@ type = 'submit']'. (테스트되지 않았지만 추측입니다.) – Arran

답변

1

당신은, 어쨌든 XPath를 선택 앞에 .가 필요합니다 때때로

.//button[@type='submit'] 

을 좀 더 정교한 XPath는 또한 도움이 될 수 있습니다

.//descendant::button[@type='submit']