سؤال

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