方法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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)