Utilize Selenium with Eclipse (Java) to validate the CSS table border style

I'm currently conducting a form test that involves leaving mandatory fields empty to verify if the field displays a red border indicating it needs to be filled before proceeding. Below is the code snippet I have implemented so far:

driver=new FirefoxDriver();
driver.manage().window().maximize();

/** Test: Open page*/
driver.get ("URL with form");

/** The following checks for a text above the form specifying mandatory unfilled fields */
driver.findElement(By.id("nextbutton")).click(); /** leave all fields blank and click on next below form */
assertEquals("The following fields are mandatory", driver.findElement(By.cssSelector("p")).getText());
assertEquals("Field 1 is mandatory", driver.findElement(By.xpath("//form[@id='genericform']/div[2]/ul/li")).getText());
assertEquals("Field 2 is mandatory", driver.findElement(By.xpath("//form[@id='genericform']/div[2]/ul/li[2]")).getText());
assertEquals("Field 3 is mandatory", driver.findElement(By.xpath("//form[@id='genericform']/div[2]/ul/li[3]")).getText());

assertTrue(isElementPresent(By.id("Field1.Value"))); /** confirms the first mandatory field is present */

To further validate, I aim to assert that the mandatory field showcases a red border along with an icon, distinguishing it from non-mandatory fields that lack the same visual cues. https://i.sstatic.net/spbhw.jpg

CSS:
border-color: #E04228; background: #FFF url("../img/icon-field-error.png") no-repeat scroll right center / 28px 22px;

The tools utilized for this test include Eclipse combined with Selenium webdriver.

Answer №1

Utilize the getCssValue() function to obtain CSS properties such as border-bottom-color, border-top-color, border-left-color, and border-right-color:

assertEquals("rgba(112, 180, 73)", element.getCssValue("border-left-color"));

It is important to note that border-color is calculated and cannot be accessed in this manner.

You can also convert the rgba value to HEX format for better legibility and usability.


In an alternative approach, you can simply verify if the input element contains both the error and input-validation-error classes:

assertEquals("block error input-validation-error", element.getAttribute("class"));

Answer №2

Appreciate your help, the latest update you provided did the trick. I made a slight modification, and now the code looks like this:

assertEquals("rgba(224, 66, 40, 1)", driver.findElement(By.id("frm-Voornaam.Value")).getCssValue("border-bottom-color"));

Adding [, 1] to the rgba values resolved the issue. Thanks a lot!

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

Unable to see Primereact styles reflected on components

After some investigation, I've pinpointed the issue to be related to preflight from tailwind. Upon reviewing the documentation, I came across this helpful information: CSS Layer It seems that using Tailwind CSS with styled or unstyled modes of PrimeR ...

Encountered an issue locating the stylesheet file 'css/style.css' that is supposed to be linked from the template. This error occurred when trying to integrate Bootstrap with Angular

<link rel="stylesheet" href="plugins/bootstrap/bootstrap.min.css"> <link rel="stylesheet" href="plugins/owl-carousel/owl.carousel.css"> <link rel="stylesheet" href="plugins/magnific-pop ...

If the SASS condition matches the variable for the background color, then

I attempted to create a conditional statement in my component using Sass @if and @else. The condition I set was that if background == var(--bg-danger), the color should be white. However, it only returned white and did not trigger the else condition. @mixi ...

I am curious if there is a wysiwyg web editor extension specifically designed for VS2010 available?

In my experience, I have been working with C#, HTML coding using VS2010 and MVC. Utilizing VS2010 has proven to be an invaluable tool for me in this process. Currently, I find myself needing to create some straightforward static web pages. I am wondering ...

Achieve the highest character count possible within HTML elements

Is it possible for a standard HTML element with defined width and height to manage characters using JavaScript, as shown in the code snippet below? <div id="text-habdler-with-width-and-height" ></div> <script> $("element& ...

What is the most effective way to add images to a table using JavaScript?

Is there a way to insert images into the "choicesDiv" without having to make changes to the HTML & CSS? Here is the table code: <table id="choices"> <tr> <td><div class="choicesDiv" value="1"></div></td> ...

The td data is appearing fragmented and not continuous in one line

Why is the td element on my webpage not appearing on a single line? The weekly report for XYZ is displaying on two lines, but I want it to be on one line. Why is the label content showing up on the next line? Output: Weekly Report for Testing project ...

What are some ways I can adjust line-height without changing the height of the cursor?

When working in a contenteditable div, I am utilizing line-height to create some spacing between lines. The following example illustrates the issue: <div style="padding: 50px; width: 90px; line-height: 2em;" contenteditable="true"> line height lin ...

Selenium is encountering an issue where it is unable to automatically download files, as the download confirmation

While reviewing someone else's code, I encountered an issue with automatically downloading PDF files from a web page using selenium. Despite setting the browser.helperApps.neverAsk.saveToDisk property to the PDF mime type, I am still getting the fire ...

Modify user profile in Selenium WebDriver using Chrome

I'm currently facing an issue with Selenium Webdriver. I need to switch the user profile from one user to another within my tests. For example, user1 is a regular user while user2 has administrative rights. I plan to run a test case using a common us ...

Guide on clicking an element within a hidden iframe using Python Selenium

I am facing a challenge in finding elements within an iframe tag. Surprisingly, the HTML source does not contain any iframe tags. However, upon inspecting the element, I can see that there is indeed an iframe tag present. How can I tackle this issue using ...

Alter the hue of a component upon being clicked

Seeking help to modify the color of my menu elements upon clicking on the "center" or "right" containers (reverting back when clicked again). Currently, the three lines in my menu are white, but I desire them to turn red when either of these containers is ...

Jenkins begins running chromedriver while in the background, similar to a headless mode operation

I have configured a Jenkins server on a Windows 10 machine. When I run a job (simply mvn test -DsuiteXmlFile=%TestSuite%), the job compiles successfully and starts tests. Initially, the first test is skipped, the second one fails, and then it starts passin ...

Using the flexslider to override CSS styles in an <li> element

I have implemented the flexslider by whoothemes on my responsive website to showcase tiles. However, I am facing an issue with setting a specific width for the tiles on various devices. Upon inspecting with Chrome, I see this code: <li style="width: 21 ...

Utilizing graphics within the Atom text editor

Hey, I have a bit of a silly question. I can't seem to figure out why these images aren't showing up on my Atom editor. Can anyone help me with this? <body> <div class="top-container"> <img src="images/clou ...

Passthrough feature is not available, GL functionality has been disabled

My recent attempt at crawling a particular website using selenium and webdriver_manager.chrome was successful in extracting elements from the site. However, upon completion of the crawl, an error message appeared in the console window stating: ERROR:gpu_i ...

Ways to format table using flex-wrap sans the use of flexbox

My HTML and CSS structure is as follows: .item { background: white; padding: 5px; display: inline-block; text-align: center; } .item > div { background: yellow; width: 60px; height: 60px; border-radius: 50%; display: table-cell; ...

Navigating the art of employing different fonts for a website

I am looking to incorporate the trainway font into my website, but I'm concerned that the user may not have it installed on their device. Is there a way to showcase text in a specific font without requiring the user to download and install it? Thank ...

Could not find element; alternative image source URL missing

Struggling to retrieve the image link for the channel icon and banner image from YouTube, but unable to find the element. Please see the image below: https://i.sstatic.net/walYR.png This is the code I attempted for the channel icon image: channel_icon = ...

Rails feature testing experiencing hiccups post Yosemite update

Following my Mac's upgrade to Yosemite, I encountered issues with some feature tests, particularly with steps involving the usage of the `fill_in` method. The problem arises on the initial fill_in within the following step definition: def sign_in v ...