0

Is there any way to retrieve values from the rect tag using Watir. I can give an example URL. There are rectangular bars on the lower part of the page. Please find it

http://www.healthgrades.com/hospital-directory/california-ca-los-angeles/good-samaritan-hospital-hgste2618d46050471?#Readmission

I have seen couple of sources but I have not got any way to get those details. Can any one help me here?

4
  • 2
    Welcome to Stack Overflow. PLEASE do not put a link to a page as an example of what you want. Links rot and become worthless, making your question of very little value for people searching for a similar answer in the future. Instead, extract ONLY the HTML source you are asking about and insert that into your question, formatted for readability. That way the important information is always visible, even if the link breaks. Also, you need to show us what you've tried toward solving this problem. Commented Apr 14, 2015 at 17:27
  • This question has value regardless of the specific example in this link. The answer is the same for any page that uses SVG elements: w3.org/TR/SVG/shapes.html. The html itself isn't present in source, so it's not an easy copy/paste. Commented Apr 14, 2015 at 18:41
  • Hi Titus, I am about to say the same. @theTinMan I need people to exactly feel the page to give clear cut answer so is the reason I have given a link there. Commented Apr 15, 2015 at 3:06
  • 1
    Imagine the question without the link. Would it make sense? That is why we need the information embedded in the question. Remove everything except the barest HTML necessary to demonstrate the problem. You can't really expect people to spend a lot of time helping you if you haven't spent at least an equivalent amount of time putting together the question. And, asking them to search a link to find the information you should have put in the question is just going to reduce your chances of getting help. You have to help us help you. Commented Apr 16, 2015 at 0:00

3 Answers 3

1

Yes, you can access it as a generic element (example only, not applicable to your code). The data element you are looking for is highcharts-data-labels.

values = browser.element(:css => "g.highcharts-data-labels")

You could also access the element using an xpath selector and can get this in Chrome by inspecting the element and asking for the xpath selector

//*[@id="highcharts-2"]/svg/g[4]/g[2]/text

Good luck!

Sign up to request clarification or add additional context in comments.

3 Comments

I raised an issue in the watir project about adding support directly. I'm honestly not sure if that is a good idea or not, but we'll see if it makes it into a future version: github.com/watir/watir-webdriver/issues/332
@titusfortner Thanks, I will follow up its progress there.
@jeff: My intention here is to get the value available on the bar, not just accessing the element.
0

you can use xpaths to select the desired rectangle. Each rectangle on the link you provided has a unique xpath. Your code could be something like this:

browser.element(:xpath, "//*[@id='highcharts-0']/svg/g[7]/g/rect[1]").flash 

Comments

0

You can access that element in one of the two ways that @jeff-price pointed out, or you could extend watir to add support for the tag.

This is not included by default since that stuff is not part of the HTML5 standard proper. With what essentially amount to 'custom' tags like this there are of course an unlimited number of potential custom tags. it is impossible to add support for all of them.

OTOH it is very easy for you to include a small snippet of code in your project that would add support for the tag to watir, which if you know your project is using it a lot, makes perfect sense.

# extend watir to allow support for custom elements not expressly defined in HTML spec

module Watir
  module Container
    def g(*args)
      G.new(self, extract_selector(args).merge(:tag_name => "g"))
    end

    def gs(*args)
      GCollection.new(self, extract_selector(args).merge(:tag_name => "g"))
    end
  end

  class G < Element
  end

  class GCollection < ElementCollection
    def element_class
      G
    end
  end
end

depending on what framework etc you are using, you can either put that into a file and require the file early in your test code, or put it into a file in a directory that is automatically loaded..

e.g. I use Cucumber, so I created a file named custom_element_support.rb with that code in it and put it into the features/support directory where cucumber will automagically load it as it starts up

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.