2016-09-02 3 views
1

내 웹 페이지의 테스트를 자동화하려고합니다. 웹 페이지에서 클래스 이름과 텍스트가있는 앵커를 선택해야합니다. 앵커는 div 요소로 묶여 있습니다. 클래스 이름이있는 앵커를 선택하는 방법

<div class="margins0300"> 
 
<a tabindex="-32768" class="buttonLinkText">Hilfe</a> 
 
</div>

나는 webdriver <a> Selenium와 인터넷 익스플로러에 액세스하려고하지만, 할 수 있지 않다. 여기 내 코드는 다음과 같습니다.

driver.FindElement(By.XPath("//a[contains(@class,'buttonLinkText') and .//text()='Hilfe']")); 

그러나 실행하면 요소가 없습니다.

누군가 나를 도와 줄 수 있다면 정말 고맙겠습니다.

답변

1

By.CssSelector()을 사용하여 요소를 찾으려고 시도하는 동안 실제로는 xpath으로 구문을 전달 중입니다.

driver.FindElement(By.Xpath("//a[@class = 'buttonLinkText' and text() = 'Hilfe']")); 

당신은 또한 아래 By.LinkText()를 사용하여이 요소를 찾을 수 있습니다 : - : - 당신은 아래 By.Xpath()를 사용하여 시도해야

driver.FindElement(By.LinkText("Hilfe")); 

을 편집 : - 당신은 여전히이 요소를 찾을 수없는 경우 요소는 다음과 같이 존재 때까지 기다려야 WebDriverWait를 사용해보십시오 : -

IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3)) 
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Xpath("//a[@class = 'buttonLinkText' and text() = 'Hilfe']"))); 

참고 : -이 요소가 frame/iframe 안에 있지 않은지 확인하십시오.

driver.SwitchTo().Frame("frame/iframe name or id"); 

//Now find the element using above code 

//After doing all stuff inside frame/iframe you need to switch back to default content 
driver.SwitchTo().DefaultContent(); 
+0

: - 만약 그렇다면 당신은 같은 요소를 발견하기 전에 그 frame/iframe을 전환해야 나는 모든 가능성을 시도했다. 게시 한 사람도 있지만 작동하지 않았습니다. –

+0

@ Shakti saxena 무슨 뜻이야? 어떤 예외가 있습니까 ?? –

+0

예. 똑같다. 요소를 찾을 수 없습니다. –

0

즉 DIV 요소가 프레임에 묶여 있었기 때문에 내가 답을 찾을 방법은 입력에 따라 @saurabhgaur에서 :

driver.Navigate().GoToUrl("https://websunp8.bk.datev.de/zws/ShowMenu.do"); 
      driver.SwitchTo().Frame("content"); 

    driver.FindElement(By.XPath("//a[@class = 'buttonLinkText' and text() = 'Hilfe']")).Click(); 
+0

'driver.FindElement (By.LinkText ("Hilfe"))를 사용할 수도 있습니다. 대신 (();)을 클릭하십시오. –

관련 문제