Selenium WebDriver中十六进制格式的getCssValue(颜色)

Selenium WebDriver中十六进制格式的getCssValue(颜色),第1张

Selenium WebDriver中十六进制格式的getCssValue(颜色

方法1:使用StringTokenizer:

String color = driver.findElement(By.xpath("//div[@]/a")).getCssValue("color");String s1 = color.substring(4);color = s1.replace(')', ' ');StringTokenizer st = new StringTokenizer(color);int r = Integer.parseInt(st.nextToken(",").trim());int g = Integer.parseInt(st.nextToken(",").trim());int b = Integer.parseInt(st.nextToken(",").trim());Color c = new Color(r, g, b);String hex = "#"+Integer.toHexString(c.getRGB()).substring(2);System.out.println(hex);

方式2:

String color = driver.findElement(By.xpath("//div[@]/a")).getCssValue("color");String[] numbers = color.replace("rgb(", "").replace(")", "").split(",");int r = Integer.parseInt(numbers[0].trim());int g = Integer.parseInt(numbers[1].trim());int b = Integer.parseInt(numbers[2].trim());System.out.println("r: " + r + "g: " + g + "b: " + b);String hex = "#" + Integer.toHexString(r) + Integer.toHexString(g) + Integer.toHexString(b);System.out.println(hex);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5086402.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存