Discovering a route with the help of CSS Selector within Selenium

Looking to locate an element using CSS Selector with Selenium in Java.

Here's the HTML snippet:

<div class="PayMeth" widgetid="PayMeth_0" id="PayMeth_0">
<div class="Icon GIFT" data-dojo-attach-point="pmN"></div>
<div class="paytMethLab" data-dojo-attach-point="pmN">Program Card<br> 
0000 000 0000 ****</div>
<div class="payMethAmtP" data-dojo-attach-point="pmAmtN">-$0.1</div>
</div>

The current path used that is not working:

By.cssSelector("div[class=paytMethLab.contains(Program Card)]")

Attempting to extract the text "Program Card". Any assistance would be greatly appreciated. Thank you.

Answer №1

Check out this basic CSS snippet.

div.paymentMethodLabel

Take a look at the following code:

WebElement paymentMethod = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.paymentMethodLabel")));
 String programCard= paymentMethod.getText();
    if(programCard.contains("Program Card"))
    {
        //add your custom logic here.
    }

Answer №2

Hooray! This is the code I utilized and it successfully worked for me :)

WebElement PaymentMethod = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.paymentMethodLabel")));
String programCard = PaymentMethod.getText();
if(programCard.contains("Program Card"))
{
    // Take necessary actions
}

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

The -webkit-box-reflect effect vanishes during the transition

I need help with this issue: The image loses its reflection during the transition until it returns at the end. Any suggestions are appreciated! Thank you! .specials-box { width: 330px; margin: 50px 0; height: 500px; position: relative; ...

Swap the text within the curly braces with the div element containing the specified text

I have an input and a textarea. Using Vue, I am currently setting the textarea's text to match what's in the input field. However, now I want to be able to change the color of specific text by typing something like {#123123}text{/#}. At this poin ...

How can one bypass an element that is not present on a webpage using Selenium with Python?

When scraping multiple similar webpages, I have encountered a situation where the same information is located under different XPATHs on some of the pages. Below are the two XPATHs that I am trying to alternate between: city_e = WebDriverWait(driver, 2 ...

The overlay image is not positioned correctly in the center

I am struggling with positioning a play icon overlay on the image in my list-group-item. The current issue is that the icon is centered on the entire list-group-item instead of just the image itself. I am working with bootstrap 4.4.1. Here is the HTML str ...

Can Three.js be used to create a compact canvas?

I've successfully implemented a three.js scene on my website where users can drag to rotate an object. However, I don't want the scene to take up the entire webpage. I tried adjusting the field parameters with the following code: renderer.setSiz ...

Looking to halt navigation in a Chrome browser immediately after performing a click action with Selenium?

Is there a way to prevent the browser from loading immediately after a click event? Are there any workarounds or JavaScript implementations for achieving this? ...

Eliminate any vacant areas within a container and shift the container, along with its contents, on the webpage

I want to eliminate the empty space within the container while maintaining some spacing around the black box, and ensure responsiveness. Additionally, how can I shift the container with its content downwards and to the right of the webpage, while still ke ...

Encountering issues retrieving modal elements for PDF download using selenium

I am currently trying to web scrape a website that displays the pdf I need in a modal view. My goal is to download or access this pdf file. However, the pdf opens up within a modal viewer where I cannot find the download button or any other element using ...

Arrange two internal divs on top of one another with the option to maintain the float

While searching for a solution to my issue, I noticed that most responses involved removing the float property. However, since I am new to CSS, I would like to explore using float and see if it's the best approach. Here is the fiddle I've been w ...

adjusting the color of link texts in a bootstrap navbar when hovering

I am trying to customize the color of the links in my Bootstrap Navigation bar when hovered over. I have attempted to apply CSS, but it is not producing the desired effect. I prefer not to alter the existing code structure, and would like to achieve the ho ...

I am having difficulty clicking the checkbox as I keep receiving a timeout exception

When attempting to click the checkbox in my code, I keep encountering a time out exception. I've tried using time.sleep(80) but it hasn't solved the issue. def __init__(self, driver): self.driver = driver def filterclick(self): try: e ...

The main function is failing to trigger the execution of my second function

I have created two functions and invoked them in the main method. However, when I run the program, only the first function gets executed in the main method, and then the program stops. If I switch the order of the functions in the main method, the first ...

The Selenium WebDriver's `driver().switchTo().defaultContent()` method seems to be having trouble switching control back to the parent window when dealing with multiple child windows

Having trouble with the Selenium WebDriver's driver().switchTo().defaultContent() method not properly switching control back to the parent window from multiple child windows. The issue I am facing pertains to the number of windows, not frames. After ...

What is the best way to implement a wait command in Selenium tests using PHPUnit?

Currently, I am in the process of creating a test using PHPUnit and Selenium for my contact page which incorporates a Google Maps slider feature. The function being written for this test is as follows: public function testContact() { $this->ope ...

Notifications for AngularJS tabs

I need help finding a method to incorporate "tab notification" using AngularJS, in order to show that there are important alerts that require attention. For example: (1) (3) TAB_ONE TAB_TWO TAB_THREE Could you provide any recom ...

Encountering AttributeError: 'NoneType' has no attribute 'get' when using Pytest

My automation python script encounters an Attribute error when attempting to run on different browsers through the terminal using this command: pytest -s -v testcase/test_login --browser Chrome The issue arises in the test_login Python main file: from sel ...

Media queries in CSS not functioning as intended

Trying to scale media requests with an image (logo) for various mobile devices like iPhone 5, 6, 6+, iPads, and large screens. Need to specify styles for portrait and landscape orientation as well. The code seems to be functioning only for iPhone 6, iPads ...

Is it possible to resize an object using JavaScript?

Is it possible to change the size of an object when loading specific data by clicking on navigation? <object id="box" width="250" height="250" data=""></object> Although the JS code loads the data, it does not change the size. document.getEl ...

The CSS code does not seem to be applied when using HTTP, however, it

After hosting my website, I noticed an issue with my CSS stylesheets. When I access my site using www.example.com, everything displays correctly. However, if I use the address http://example.com, only the HTML body shows up without any CSS styling. Can a ...

Attention required prior to closing the (x) button on a Chrome modal popup alert

I've been attempting to close the popup modal confirm alert using various methods, but unfortunately none have been successful. I tried using popupcsd.onbeforeunload and popupcsd.onUnload, with no luck. The code snippet I'm working with is: wind ...