Utilizing the `contains` CSS Selector in Selenium WebDriver to Retrieve Elements

When attempting to utilize CSS Selector with contains() in Selenium WebDriver, I encountered a NullPointerException.

Could anyone provide assistance with this issue?

private static final String testcode = "p:contains('Notes')";

public String getTextCode(String codes) throws Exception {
    String jc = driver.findElement(By.cssSelector(codes)).getText();
    return jc;
}

Answer №1

The specifications do not provide support for this. Consider utilizing XPath instead.

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

What might be causing the JSON document to remain partially unused?

I'm experimenting with fetching JSON data from an external source for practice. I've set up all the code, but I keep encountering an error stating that the document is not fully consumed. Despite watching tutorials and reading guides, I can' ...

Upon completion of filling out the form using Python code, Selenium automatically closes the browser

I am currently using Selenium to automate form filling with forminfo.py for the given information. At the moment, I am testing it on Instagram to troubleshoot everything. Initially, I have set it up to check if the Google Chrome driver is already installed ...

Encountering a null pointer exception when attempting to declare a WebElementFacade within a page object

While attempting to implement the page object model in Serenity BDD, I encountered a null pointer exception when declaring WebElementFacade in my page object. Below is the code for my page object class: package PageObjects; import net.serenitybdd.core.an ...

Transforming website content into HTML code

I am in need of a solution to convert a webpage into an HTML page programmatically. I have researched several websites, but the information provided only covers converting pages into PDF formats. Currently, my program involves saving a page as .html and th ...

An error occurred while attempting to convert a VALUE_NUMBER_FLOAT token into an instance of java.sql.Timestamp

I am working on a RESTful API implemented in Jersey 2.17 with Jackson on JDK8, following the JSON style. The API is designed to accept a Java object that includes the following field: @JsonProperty("processEndTime") public Timestamp getRunDate() { ret ...

Utilize Python's Selenium webdriver to operate Firefox in the background

Currently, I am involved in a website scraping endeavor utilizing Selenium with Python. One question that has crossed my mind is whether it's feasible to initiate the Firefox browser in the background or launch Firefox on a separate workspace within U ...

What is the significance of the ignoreProtectedModeSettings feature in the IE driver that enables Protractor to locate elements by their id?

Currently, I am delving into Protractor by crafting a straightforward test: describe('Tick Tack Toe game', function() { it('marks positions as played', function() { browser.ignoreSynchronization = true; browse ...

The art of Python's conditional statements and logic

I am new to using Selenium and Python, and I am trying to grasp the concept of conditional statements. However, it seems that my code is not taking the second condition into consideration: What I am attempting to do: https://i.stack.imgur.com/oFqjQ.png ...

`Inefficient functioning of Selenium Webdriver: Identifying the Issue`

I wrote a program designed to log in to TextNow, sign in, and call any number efficiently. However, when I run the script, everything works except for the final functionality. I am unsure of where the mistake lies, so I would appreciate any guidance or sol ...

Having difficulty finding an element with a changing id

Having trouble finding an element with a constantly changing id. Here's the HTML code: <a id="A7632AF8-BE67-4AEA-9621-437B54235111" target="K2MenuSystemMainFrame" title="New Second Level Menu Item" href="https://thehubtest.cargill.com/Runtime/Run ...

Navigating dynamic steps in cucumber can be done effectively without relying on the AfterStep hook

I'm currently utilizing cucumber(info.cukes)-Selenium for executing automation tests. Presently, I am faced with a situation where a specific step could occur at any stage of the process. As a result, I need to create a cucumber scenario that can con ...

Tips for selecting the correct date on a DatePicker using selenium?

I am facing an issue with my selenium test related to a date picker on a webpage. The task is to select a specific date (e.g., 14/2/2012) by clicking on the correct day. However, the date picker is generated using jQuery as shown in the code snippet belo ...

Selenium Firefox headless proxy not functioning as expected

Currently utilizing Ubuntu Server 17.04. In an attempt to configure my proxy in selenium, I have encountered issues. The proxy being used is from . Essentially, only IP addresses that I have allowed will have access to the proxy, and I must use the provid ...

What is the process for including a library in a Java project that does not have JAR files?

Recently, I developed a Java project with the intention of incorporating a JSON library. After conducting some research on various JSON libraries available, I noticed that none of them provided JAR files as part of their package. Undeterred, I proceeded t ...

Is there a way to select a Dropdown menu choice on a website by utilizing VB.NET and Selenium?

Currently, my main goal is to access the Supplier section on the website. I have included a screenshot of the source code for reference. At this point, I have successfully logged in to the site, but now I need to navigate to the next screen by clicking o ...

What is the best way to utilize GSON for deserializing an array containing various objects

When handling JSON data, it often comes in a specific format like the example below: [ { "albums" : [ {"id":"0", "name":"name"}, {"id":"1", "name":"name"} ], "name":"name" }, { "tracks" : [ {"id":"0", "name":"name", ...

issue with webdriver manager when operating through a proxy server

When trying to use webdriver-manager for execution, I encountered the following issue: webdriver-manager update --proxy=https://proxy.company.com:8080 Upon running the command above, I got the following error message: webdriver-manager: using local ins ...

In iOS device web automation, the button remains disabled even after populating a text field

I'm currently working on automating a web application using Appium with the Java client. As part of my automation process, I need to input text into a field, enable the 'continue' button, and then proceed to click it. Initially, I attempted ...

Can anyone provide guidance on locating the parent of a pseudo element with Selenium WebDriver?

Is there a way to retrieve the parent web element of a pseudo element (if we can call it the parent) using JavaScript? I know that Selenium's methods for searching for web elements are not suitable for pseudo elements, but JavaScript does allow manipu ...

Using a single selenium session across multiple test cases

Currently utilizing JUnit and Selenium for my testing. I am interested in logging into a web page once, then proceeding to run two test cases without initiating a new browser/session each time. If the "logging in" step is performed within the setUp() met ...