2012-01-20 7 views
0

내 페이지에 두 개의 요소가 있습니다 (두 개의 '취소'요소).Selenium을 사용하여 ExtJS의 요소를 클릭하는 방법?

<div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen1179"> 
Cancel 
</div> 

<div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen2951"> 
Cancel 
</div> 

두 번째 요소는 어떻게 클릭합니까? 분명히, 나는 방문마다 무작위로 생성되기 때문에 우리는 이드가 될 수 없다. 무엇을 사용할 수 있습니까?

  1. 항상 단지 2 페이지에 버튼이 '취소'를, 그리고 당신은 항상 2 일 필요
  2. ,

사용 //div[text()="Cancel"][2] XPath는 선택, 아니면 그냥 찾을 :

답변

2


1. 주어진 메커니즘을 사용하여 현재 컨텍스트 내의 모든 IWebElements를 찾는 FindElements 메서드를 사용하십시오. (이 경우, 당신은 항상 당신이 찾고있는 요소의 인덱스를 알 필요가있다.)

IWebDriver driver = new FirefoxDriver(); 
IList<IWebElement> cancelDivs = driver.FindElements(By.XPath("//div[text()='Cancel']")); 
cancelDivs[1].click(); //zero-base index 


2. 그 버튼을 비는 ExtJS ID로 식별 할 수있는 다른 섹션에 취소하는 경우 속성. 다른의 ExtJS 클래스 속성에 의해 식별 될 수


3. 그 버튼은 다른 섹션에 취소하는 경우

IWebElement secondCancelDiv = driver.FindElement(By.XPath("//div[@id='footer']//div[text()='Cancel']")); 
secondCancelDiv.Click(); 


<div id='header'> 
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen1179">Cancel</div> 
</div> 
<div id='footer'> 
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen2951">Cancel</div> 
</div> 
. ([텍스트() = "취소"] // DIV)`XPath는 =, 더 정확하게

<div id='ext-gen1060' class='x-grid3-body'> 
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen1179">Cancel</div> 
</div> 
<div id='ext-gen2555' class='x-toolbar-right-row'> 
    <div unselectable="on" class="x-grid-cell-inner x-unselectable" style="text-align: left; " id="ext-gen2951">Cancel</div> 
</div> 


IWebElement secondCancelDiv = driver.FindElement(By.XPath("//div[@class='x-toolbar-right-row']//div[text()='Cancel']")); 
secondCancelDiv.Click(); 
0

하는 경우 둘 다 클릭하고 두 번째를 클릭하십시오.

+0

을 (의미있는 것을 사용) [2]'. 두 개의 div 요소가 형제가 아닌 경우에도 작동합니다. –

관련 문제