짧은 xpath보다 긴 xpath를 평가하는 데 걸리는 시간에 큰 차이가 있습니까?
Ex. By.id("id1")
내가 너희를 물어 기쁘다
By.Xpath("//*[@id='id1']")
Webdriver Xpath 성능
3
A
답변
13
를 사용하여 사이
/div[@id = 'id1']/label[contains(text(), 'Hello')/../../descendant::input
및
//input
무엇의 차이에 대한 사이의 성능 차이가 나는 대답이 놀라운 발견 .
- 짧은 XPath는 긴 XPath는보다 빠른 아니라 파이어 폭스 이름으로 검색에 많은
- 에 의해으로 긴 XPath는하지만, (때로는 빨리) 짧은 XPath를 가진 죽은 열 인터넷 익스플로러에
- 보다 빠르다 .name을이다 XPath는보다 느린 많은 이 사이먼 스튜어트가 다시 제공 된 지침의 얼굴에 날아 것으로 보인다
: IE의 XPath는 성능을, 그래서의 곡물로 가져 것 소금,하지만 아래 코드에서는 꽤 일관성이 있습니다.
나는 이것을 보여주는 간단한 테스트를 작성했다.
파이어 폭스 드라이버를 사용 : 그것은이 출력을 제공하는 구글
package com.PeterNewhook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class FooTest {
public static void main(String[] args) {
long start;
long end;
WebDriver driver;
String longXpath = "/html/body/span[@id='main']/center/span[@id='body']/center/form/table/tbody/tr/td[2]/div[@class='ds']/input[@name='q']";
String shortXpath = "//input[@name='q']";
String elementId = "q";
System.out.println("Using Firefox driver.");
driver = new FirefoxDriver();
driver.get("http://google.com");
start = System.nanoTime();
driver.findElement(By.xpath(longXpath));
end = System.nanoTime()-start;
System.out.println("The long XPath lookup took " + (double)end/1000000000.0 + " seconds.");
start = System.nanoTime();
driver.findElement(By.xpath(shortXpath));
end = System.nanoTime() - start;
System.out.println("The short XPath lookup took " + (double)end/1000000000.0 + " seconds.");
start = System.nanoTime();
driver.findElement(By.name(elementId));
end = System.nanoTime() - start;
System.out.println("The By.name lookup took " + (double)end/1000000000.0 + " seconds.");
driver.close();
System.out.println("\nUsing Internet Explorer driver.");
driver = new InternetExplorerDriver();
driver.get("http://google.com");
start = System.nanoTime();
driver.findElement(By.xpath(longXpath));
end = System.nanoTime()-start;
System.out.println("The long XPath lookup took " + (double)end/1000000000.0 + " seconds.");
start = System.nanoTime();
driver.findElement(By.xpath(shortXpath));
end = System.nanoTime() - start;
System.out.println("The short XPath lookup took " + (double)end/1000000000.0 + " seconds.");
start = System.nanoTime();
driver.findElement(By.name(elementId));
end = System.nanoTime() - start;
System.out.println("The By.name lookup took " + (double)end/1000000000.0 + " seconds.");
driver.close();
}
}
에있는 검색 창을 찾습니다.
긴 XPath 조회에는 0.13667022 초가 걸렸습니다.
짧은 XPath 조회에는 0.024628577 초가 소요되었습니다.
By.name 조회에 0.025209911 초가 소요되었습니다.
Internet Explorer 드라이버를 사용 중입니다.
긴 XPath 조회에는 0.196125248 초가 걸렸습니다.
짧은 XPath 조회에는 0.164044262 초가 걸렸습니다.
By.name 조회에 1.005109964 초가 걸렸습니다.
관련 문제
- 1. 셀레늄/WebDriver 운전 IE에 의한 XPath 해석
- 2. XML 읽기의 XPath 성능
- 3. XPath 대 DOM의 성능
- 4. executeScript WebDriver
- 5. WebDriver : executeScript()가 BindException을 발생시킵니다.
- 6. Xpath 질문 Xml Xpath
- 7. Selenium WebDriver with Selenium-webdriver gem을 설정하는 방법
- 8. Grails webdriver installation error
- 9. Webdriver 대기 시간 문제
- 10. Selenium Webdriver Mouse
- 11. WebDriver HtmlUnitDriver NoSuchElementException
- 12. 셀레늄 webdriver 예외
- 13. 재생 기능이있는 Webdriver (ChromeDriver)?
- 14. watir-webdriver + RWebSpec
- 15. Webdriver : 그리드와 상호 작용
- 16. Webdriver 테스트 구성 방법
- 17. 거기에 어떤 차이가있다 Watir Vs Watir-webdriver xpath 처리에 대 한
- 18. Selenium webdriver : browserbot의 대체품은 무엇입니까?
- 19. Selenium2 (WebDriver)에 지원되는 브라우저
- 20. webdriver-test를 사용할 수 없습니다.
- 21. Watir-webdriver 문제가 options.yml 파일
- 22. Selenium WebDriver 및 DropDown Box
- 23. Selenium webdriver MSTEST 병렬 테스트
- 24. Regd : WebDriver on secure 인증서
- 25. Mac에서 firefox-x11을 사용하는 WebDriver
- 26. ipad 웹 응용 프로그램을위한 Webdriver?
- 27. Webdriver + HtmlUnitDriver + Java + 드롭 다운
- 28. webDriver 용 Java 시뮬레이션 클릭
- 29. 셀레늄 webdriver IE 버튼 문제
- 30. 다른 XPath 요소를 기반으로 요소를 찾을 XPath