Selenium WebDriver get text from CSS property “content” on a ::before pseudo element

后端 未结 2 850
时光取名叫无心
时光取名叫无心 2020-12-01 07:16

I am trying to verify the text \"The information provided is either invalid or incomplete.\" is displayed using Selenium/WebDriver in Java.

I have the following HTML

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 07:35

    Tried the same, works for me.

    Created sample html file :

    
    
    
    
    
    
    
    

    My name is Donald

    I live in Ducksburg

    Reused Nilesh's code

        String script  = "return window.getComputedStyle(document.querySelector('p#b'), ':after').getPropertyValue('content')";
        JavascriptExecutor js = (JavascriptExecutor) UIKeyWords.getUIDriver();
        String contentValue = (String) js.executeScript(script);
        System.out.println(contentValue);
    

提交回复
热议问题