How to check the bold appearance of a certain field in selenium

I am trying to automate a script manual (using selenium in java) to check the bold appearance of a certain field (labels: which indicates a required field) on a web page. what can be the possible functions of selenium java for checking the bold appearance of a certain element (there is no information about the appearance in the class)

+3
source share
4 answers

You can check font-weight using the method style()(if you really use Selenium-Webdriver).

So say you have HTML:

<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 div field label (in Ruby, the following is stated: although this should be possible in 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 
+2

WebDriver ( Java) 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"));

( 700 bold)


Selenium RC . , font-weight ( fontWeight ).

+4

Justin Ko style("font-weight"), python value_of_css_property("font-weight")

>>> element = self.wd.find_element_by_id("some-id")
>>> element.value_of_css_property('font-weight')
u'700'
>>> element.style('font-weight')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'WebElement' object has no attribute 'style'

http://code.google.com/p/selenium/source/browse/py/selenium/webdriver/remote/webelement.py#132

, , , -, , .

+1

, , label_required, python

els = driver.find_elements_by_css_selector(div[class*=label_required])
self.assertTrue(len(els) == [known value of required fields on page])

java (Note: I am not writing java code, so the syntax may be incorrect):

import static org.junit.Assert.assertTrue;
WebDriver driver = new FirefoxDriver();
WebElement els=driver.findElements(By.cssSelector("div[class*=label_required]"));
assertTrue(els.length == [known value of required fields on page]);
0
source

All Articles