Asked  7 Months ago    Answers:  5   Viewed   196 times

I have an SVG object with a few rectangle elements. Using geckodriver, I am trying to click on one of the main SVG object. However with xpath-checker I am unable to detect the proper xpath for the same.

Till now, I am able to drilldown through xpath upto:

id('avg_score_chart')/div/div[1]/*[local-name()='svg' and namespace-uri()='']

My HTML code is as follows:

<div id="avg_score_chart" class="chart" style="height: 250px; color: black ! important; overflow: hidden; text-align: left;">
<div class="amcharts-main-div" style="position: relative;">
<div class="amcharts-chart-div" style="overflow: hidden; position: relative; text-align: left; width: 525px; height: 212px; padding: 0px;">
<svg version="1.1" style="position: absolute; width: 525px; height: 212px; top: 0.450012px; left: -0.5px;">
<desc>JavaScript chart by amCharts 3.17.1</desc>
<g transform="translate(60,52)">
<g transform="translate(96,41)">
<g transform="translate(96,123)">
<g transform="translate(96,123)">
<path cs="100,100" d="M0.5,0.5 L0.5,-81.5 L30.5,-81.5 L30.5,0.5 L0.5,0.5 Z" fill="rgb(242,244,28)" stroke="rgb(242,244,28)" fill-opacity="0.8" stroke-width="1" stroke-opacity="0.8">
<g transform="translate(318,123)">
<g transform="translate(318,123)">
<g transform="translate(318,123)">

Can anyone help me out please?



Try following XPath and let me know if problem still persist:


For <g> elements:



Finally, this should be nearly the best option:

//div[@class="portlet light boxshadow"][contains(.,"Store Wise Performance")]/div//div[@class="amcharts-chart-div"]/*[name()="svg"]//*[name()="g"]/*[name()="path" and @fill="rgb(242,244,28)"]
Tuesday, June 1, 2021
answered 7 Months ago

To invoke click() on the reCaptcha checkbox as the element is within an <iframe> you need to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use the following solution:

    • Code Block:

      public class ReCaptcha_click {
          public static void main(String[] args) {
              System.setProperty("", "C:\Utility\BrowserDrivers\chromedriver.exe");
              ChromeOptions options = new ChromeOptions();
              WebDriver driver = new ChromeDriver(options);
              new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name, 'a-') and starts-with(@src, '')]")));
              new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.recaptcha-checkbox-checkmark"))).click();
  • Browser Snapshot:


Tuesday, June 15, 2021
answered 6 Months ago

This error message...

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

You need to take care of a couple of things:

  • Ensure that you have downloaded the exact format of the ChromeDriver binary from the download location pertaining to your underlying OS among:

    • For Linux OS
    • For Mac OSX
    • For Windows OS
  • Ensure that /etc/hosts file contains the following entry: localhost 
  • Ensure that ChromeDriver binary have executable permission for the non-root user.

  • Ensure that you have passed the proper absolute path of ChromeDriver binary through the argument executable_path as follows:

    with webdriver.Chrome(executable_path=r'C:pathtochromedriver.exe', chrome_options=chrome_options) as driver:
  • So your effective code block will be:

    options = Options()   
    options.add_argument('--no-sandbox') # Bypass OS security model
    options.add_argument('--disable-gpu')  # applicable to windows os only
    options.add_argument("--disable-dev-shm-usage")  # overcome limited resource problems
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    with webdriver.Chrome(executable_path=r'C:pathtochromedriver.exe', options=options) as driver:
        driver.set_window_size(800, 460) # takes two arguments, width and height of the browser and it has to be called before 
        driver.get("file:\"+url) # takes one argument, which is the url of the website you want to open
        driver.find_element_by_tag_name('body').screenshot(output)  # avoids scrollbar

Mandatory Considerations

Finally, to avoid incompatibility between the version of the binaries you are using ensure that:

  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v79.0.3945.36 level.
  • Chrome is updated to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.


You can find a couple of reference discussions in:

  • Python Selenium “Can not connect to the Service %s” % self.path in linux server
  • selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe while opening chrome browser
  • How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?
Friday, August 6, 2021
answered 4 Months ago
public class LoginPageTest extends IntegrationTest {

private HtmlUnitDriver driver;

public void setup() throws MalformedURLException, UnknownHostException{
    driver = new HtmlUnitDriver(true);

public void testAuthenticationFailureWhenProvidingBadCredentials(){


public void testAuthenticationSuccessWhenProvidingCorrectCredentials(){



That's how I do it for example.

EDIT: I just noticed comments. Anyway my code shows how you test the actual login page with Selenium.

Saturday, August 7, 2021
answered 4 Months ago

First of all, you cannot use such a convoluted xpath, that kills the readability of your page objects. Your selectors should be as much concise as possible. Secondly, you should not use XPATH and use CSS selector. Now coming back to your question,

 WebElement b;

or try

 WebElement b;
Thursday, November 18, 2021
answered 3 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :