解析对我不起作用 - 在使用getText()将'newSocket'作为String获取之后,我正在尝试将其解析为double,并且在运行测试后出现异常错误。请帮忙
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumPractice2investing {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\automation\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.investing.com");
driver.navigate().refresh();
WebElement e1 = driver.findElement(By.id("searchTextTop"));
e1.sendKeys("BTC/USD");
Thread.sleep(5000); // Wait until it is loaded
WebElement e2 = driver.findElement(By.id("symbol_BTC/USD"));
e2.click();
Thread.sleep(5000);
WebElement e3 = driver.findElement(By.id("last_last"));
String newSocket = e3.getText();
Thread.sleep(1);
double CurrentSocketValue = Double.valueOf(newSocket); // Getting Exception error here
答案 0 :(得分:0)
答案 1 :(得分:0)
它是空字符串。原因是这个数字是这样收到的,#2,7; 2,749.79"有了标点符号,我找到了一个忽略标点符号的解决方案并解决了它(在上面添加了评论)