Having difficulty getting CSSCount to function properly

After attempting to follow the steps outlined in this particular blog post in order to obtain a count of CSS locators, I encountered an issue with the method provided:

public static int getCSSCount(String cssLocator) {
    String jsScript = "var cssMatches = eval_css(\"%s\", window.document);cssMatches.length;"; 
    return Integer.parseInt(selenium.getEval(String.format(jsScript, cssLocator))); 
}

The method call looked like this:

getCSSCount("div[class='team-name'] a");

Despite following the instructions precisely, I consistently faced the following exception:

FAILED: com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: unterminated string literal at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97) at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91) at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262) at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:471)

Answer №1

After implementing the code provided, I can confirm that it successfully worked for me as well. In my case, the cssLocator used was:

"div[class=\'callout\'] a".

My suspicion is that the issue stemmed from an un-escaped single quote being passed into the JavaScript function.

Answer №2

This method has been quite effective for me...

It seems like there might be a small syntax error in the CSS selector you are using...

Give this a shot -

getCSSCount("div[class=team-name]");

Additionally, if the elements you want to count are located inside an iframe, remember to use selenium.selectFrame(...); to switch focus to that specific frame.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Oops! There was an unexpected error: TypeError - It seems that the property 'title' cannot be read because it is undefined

HTML document example <ion-header> <ion-toolbar color="danger"> <ion-buttons> <button ion-button navPop icon-only> <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon> </button> ...

Steps to retrieve the central coordinates of the displayed region on Google Maps with the Google Maps JavaScript API v3

Is there a way to retrieve the coordinates for the center of the current area being viewed on Google Maps using JavaScript and the Google Maps JavaScript API v3? Any help would be greatly appreciated. Thank you! ...

The JavaScript code successfully updates the text displayed on the button, but for some reason, the changes are not reflected when the button is clicked and the text received from the

In my current project, there is a textbox accompanied by a button labeled "Activate". Whenever the user modifies the text in the textbox, the button's label switches to "Search". In the backend code, it distinguishes between the button displaying "Sea ...

Switch the div class when clicked, and revert it when the body is clicked

Allow me to elaborate on the issue: I currently have <div class="contact"> <div id="form"></div> <div id="icon"></div> </div> My goal is to change the class of .contact to .contactexpand (or simply ...

CSS3 keyframes hover animation for Firefox

I implemented keyframes animation for a div on mouse hover using pure CSS3. The animation runs smoothly on all browsers (Google Chrome, Safari, IE, Opera) except for Firefox! I'm puzzled as to why it doesn't work only in Firefox. The animation ...

Implementing checkboxes for each API data in JavaScript

I am fairly new to this and I am currently working on a to-do list. I want to include a checkbox next to each item from the API to indicate whether it has been completed or not. <script type="text/javascript"> fetch('http://localhos ...

Fetching/Inputting data in Ruby Testing Framework

Can someone please assist me before I lose my mind? I'm currently using Ruby Test Unit alongside Selenium Webdriver for my tests. Each test begins with a login function, and I would like to retrieve the username and password values from a central scr ...

`Switch up the UberMenu main menu icon when a submenu is in use`

Recently, I started using the UberMenu plugin on my WordPress website. Here is a handy guide to an example menu: link. Interestingly, my menu is structured exactly the same way, except that the submenu only opens when clicked rather than hovered over. I ...

Do you have any suggestions on how to send "iframe.contents()" to a PHP Script via Ajax?

I'm currently facing an issue in my code where I have an iFrame loading dynamic content, similar to a webpage (B.html) inside another page (A.php). On "A.php", users can edit the content of "B.html" inline. However, after the editing process is comple ...

Learn the process of retrieving information and saving it in the React Context API!

Just diving into the world of Context API for the first time, so please bear with me! I'm currently attempting to fetch data from a local JSON file and store the response in the Context API for global use throughout my app. However, when I run the a ...

Eliminate redundant code within the reducer function in a React application

I have recurring code in reducers where only the property name changes. How can I refactor this to eliminate redundancy? const reducer = (state, action) => { switch (action.type) { case ADD_ITEM: { if (state.toggleCost) { let l ...

Is there a way to generate a report that mirrors the sequence of my test case executions? I am looking to configure this feature

Currently, I am using Selenium and Java along with ReportNG for my automation suite. After running the tests, I receive the report in ascending order by default. However, I would prefer to have the report display in the order of execution. Is there a way ...

Using the two-pointer technique in JavaScript to tackle the reverse vowel dilemma

I encountered the Reverse Vowel problem on Leetcode and decided to tackle it using the Two Pointers pattern. Here is the implementation: var reverseVowels = function(s) { let arrS = s.split('') let vowels = ['a','e',&a ...

There seems to be an issue: [ng:areq] - Please visit the following link for more information: http://errors.angularjs.org/1

Hey there! I'm in need of some assistance. Just started learning Angular and tried setting it up like this. This is the structure of my files: AboutController.js function AboutController( $scope ){ $scope.data = { "data" : { "name ...

After clicking the create button in AngularJS, the ngModel values become empty

My form has been simplified by using ngRepeat to create the input fields. The attributes for each item are defined in my controller. Below is the code for the ModalCtrl: ... $scope.form = [ { label: 'First Name', fieldType: 't ...

Locate data objects using JavaScript keys

My object looks like this: { sunday: {status: "open", opening_time: "11:30 am", closing_time: "12:00 pm"}, monday: {status: "close", opening_time: "", closing_time: ""}, tuesday: {status: "close", opening_time: "", closing_time: ""}, wednesday: {st ...

Adding a Key Value pair to every object within an Array using TypeScript

I have two arrays - one contains dates and the other contains objects. My goal is to include the dates as a key value pair in each object, like this: {"Date": "10-12-18"}. dates: ["10-12-18", "10-13-18", 10-14-18"] data: [ {"name":"One", "age": "4"} ...

Retrieve data from two databases and display the information from two separate arrays on a single ejs page after making two separate database calls

Currently, I am faced with a challenge where I need to render a page by passing two arrays that are populated by two separate database calls. It seems that when I only pass one array to the ejs page, everything works as expected. For a single array, my a ...

Tips for retrieving information in addition to a promise

This particular function is designed to handle stock account data in a sequential manner, reminiscent of a state machine, with the ultimate goal of placing a sell order. The challenge I am facing is how to efficiently pass the account data to each state w ...

Is OnPush Change Detection failing to detect state changes?

Curious about the issue with the OnPush change detection strategy not functioning properly in this demonstration. My understanding is that OnPush change detection should activate when a property reference changes. To ensure this, a new array must be set e ...