How to handle overlapping elements

Hi,

I have a graph displaying different prices of different products. I need to click on each of the data points. However, some of the data points overlap when 2 products have the same price. Thus, I would get an error that another element would receive the click. How should I handle this?

I tried the following script:

WebDriver driver = DriverFactory.getWebDriver()

// get a collection of datapoints

def datapoints = driver.findElements(By.cssSelector(’.data.shape.circle’))

//get the total number of data points

def countdata = datapoints.size()

println(countdata) //print the total number of data points

//loop over each datapoint

datapoints.each({ def point ->

WebUI.executeJavaScript(“arguments[0].click”, Arrays.asList(point))

It is marked as PASSED “Execute JavaScript ‘arguments[0].click’ successfully”, however, the data points are not clicked.

I’ve run into this before, I use the javascript click method as well. I’ve stored it as a keyword and call the keyword to click the object. However I did notice that you dont’ have the web element piece. Could this be what is missing?

public class JavascriptClick {

@Keyword

def clickUsingJS(TestObject to) {

WebDriver driver = DriverFactory.getWebDriver()

WebElement element = WebUiCommonHelper.findWebElement(to, 30)

JavascriptExecutor executor = ((driver) as JavascriptExecutor)

executor.executeScript(‘arguments[0].click()’, element)

}

}

Hi B L,
Thanks for your reply. I’ve already tried creating a custom keyword but it didn’t work 'cause it gave me an error that “click() is not a function”. So, I’ve insert the JS itself into my script. It says that the click was successful but the data point was not actually clicked.