문제

I want to verify text is a link or not ..How can i do with ruby in webdriver.

value1 = $driver.find_element(:xpath => "//div[@class='xxx']/div[6]/div/p/span[2]").text
value2 = $driver.find_element(:xpath => "//div[@class='xxx']/div[6]/div/p/span[2]/a").text

here first i will get the text from xpath then i want to verify that text is link or not.

도움이 되었습니까?

해결책

Depends on how hard you want to check.

response = nil
begin
  response = Net::HTTP.get_response(URI(value1))
rescue
end

response && response.code_type == Net::HTTPOK

Will check that it is a valid URL that points to a working server that honors a GET request without redirecting.

value1 =~ URI.regexp(['http', 'https']) 

will just check that it looks like a valid HTTP or HTTPS URL.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top