I am trying to automate a manual script (using selenium in java) to check the bold appearance of a certain field(label:which stands for mandatory field) on a web page . what can be the possible selenium java functions to verify the bold appearance of certain element(In class there is no information about the appearance)
With WebDriver (in Java), you can use getCssValue(). With Selenium RC, see this technique, just use font-weight (or fontWeight depending on the usage). Save this answer.
We can verify the color of a webelement in Selenium webdriver using the getCssValue method and then pass color as a parameter to it. This returnsthe color in rgba() format. Next, we have to use the class Color to convert the rgba() format to Hex.
With WebDriver (in Java), you can use getCssValue().
import static org.junit.Assert.assertTrue;
(...)
// assuming elem is a healthy WebElement instance, your found element
String fontWeight = elem.getCssValue("font-weight");
assertTrue(fontWeight.equals("bold") || fontWeight.equals("700"));
(since 700
is the same as bold
)
With Selenium RC, see this technique, just use font-weight
(or fontWeight
depending on the usage).
You can check the font-weight using the style()
method (assuming you are actually using Selenium-Webdriver).
So say you have HTML like:
<body>
<div id='1' style='font-weight:normal'>
<div id='2' style='font-weight:bold'>Field Label</div>
<div id='3'>Field</div>
</div>
</body>
You can do the following to check the font-weight of the field label div (the following is in Ruby, though similar should be possible in the other languages).
el = driver.find_element(:id, "2")
if el.style('font-weight') >= 700
puts 'text is bold'
else
puts 'text is not bold'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With