Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为具有多个标记的元素断言标记_Java_Html_Eclipse_Selenium_Tags - Fatal编程技术网

Java 为具有多个标记的元素断言标记

Java 为具有多个标记的元素断言标记,java,html,eclipse,selenium,tags,Java,Html,Eclipse,Selenium,Tags,作为测试的一部分,我需要检查给定元素的标记和样式。该元素在页面上显示为(粗体、斜体和居中): 如果我添加另一行来断言em标记,它将返回strong,我不知道如何通过它 assertEquals ("em", driver.findElement(By.xpath("//*[text()='TEST']/strong")).getTagName(); 另外,当我尝试下面的方法来获取样式属性时,它无法通过em和strong标记。(org.junit.ComparisonFailure:expect

作为测试的一部分,我需要检查给定元素的标记和样式。该元素在页面上显示为(粗体、斜体和居中):

如果我添加另一行来断言em标记,它将返回strong,我不知道如何通过它

assertEquals ("em", driver.findElement(By.xpath("//*[text()='TEST']/strong")).getTagName();
另外,当我尝试下面的方法来获取样式属性时,它无法通过em和strong标记。(org.junit.ComparisonFailure:expected:但was:)。 这对p标记中只有文本和对齐方式的元素有效

assertEquals ("text-align: center;", driver.findElement(By.xpath("//*[text()='TEST']")).getAttribute("style"));

findElement将查找
TEST
,因此您将得到[]

assertEquals ("text-align: center;", driver.findElement(By.xpath("//*[text()='TEST']")).getAttribute("style"));
要获取样式属性,请在
标记处进行操作

driver.findElement(By.xpath("//p")).getAttribute("style"); 
在一条语句中验证所有内容:下面使用的XPath给出了一个元素,该元素的p居中,有一个带强标记的强调文本。如果找到该元素,则验证您的条件

driver.findElement(By.xpath("//p[@style='text-align: center;']/em/strong[text()='TEST']")
driver.findElement(By.xpath("//p")).getAttribute("style"); 
driver.findElement(By.xpath("//p[@style='text-align: center;']/em/strong[text()='TEST']")