Thursday, July 31, 2014

Selenium: svg tags and Css Selectors


SVG tags and Css Selectors


Sample:
<div id="fsdf" class="dsdfds"/>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="264" height="250"/>
        <defs/>
        <rect rx="dsfd" ry="45" fill="sdf"/>
                <g class="highcharts-tracker" zIndex="1"/>  
                    <g />  
                        <rect fill="rgb(123,222,222)   NEED TO GET HERE  />


example :
1. //[local-name()='svg']
2. //*[local-name()='svg']
3. //*[local-name()='svg']//*[local-name()='g']
4. //*[local-name()='svg']//*[local-name()='g'][1]
5. //*[local-name()='g'][@class='highcharts-tracker']/*[local-name()='g']
6. //*[local-name()='g'][@class='highcharts-tracker']/*[local-name()='g']/*[local-name()='rect'][1]

7. //*[@class='highcharts-tracker']/*[local-name()='g']/*[local-name()='rect'][1]
8. //*[@class='highcharts-tracker']//*[local-name()='rect'][1] 

driver.findElement(By.xpath("//*[@class='highcharts-tracker']//*[local-name()='rect'][1]")).click()


OTHER EXAMPLES
driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='Me']"));  
driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='You']"));  
driver.findElement(By.cssSelector("//*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']//*[local-name()='tspan' and text()='None']")); 

Ref:
http://automatethebox.blogspot.in/2012/10/how-to-locate-element-in-svg-tag-in.html
https://code.google.com/p/selenium/issues/detail?id=6441

 
 
  

6 comments:

  1. this is really too useful and have more ideas from yours. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.
    School Logo Design UK

    ReplyDelete
  2. this is really too useful and have more ideas from yours. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.
    New Zealand education Consultants in Chennai

    ReplyDelete
  3. Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
    Selenium Training Institute in Chennai
    Selenium Training in Chennai
    Trending in Selenium Training in Velachery.

    ReplyDelete
  4. How to use CSS Selector as Locator is one of the important point to note down, What is CSS Selector ?
    CSS Selector is combination of an element selector and a selector value which identifies the web element within a web page. The composite of element selector and selector value is known as Selector Pattern.
    Know more:
    Selenium Training in Chennai
    Selenium Training in Velachery

    ReplyDelete