我有一个字符串(在我的 main 方法中初始化),我想在新的 JFrame 窗口方法中使用它。我有以下代码:
public static void main(String[] args){
WebElement link = driver.findElement(By.xpath("//*[@id='pagecontainer']/section/ul/li[1]/a"));
String linkLocation = link.getAttribute("href");
}
对于我的 JPanel 中的 JButton 的主要方法和以下代码
public void actionPerformed(ActionEvent e)
{
desk.browse(new URI(linkLocation));
}
如何让它发挥作用?
最佳答案
像这样的事情可能对你有帮助:
public String LinkLocation(){
WebElement link = driver.findElement(By.xpath("//*[@id='pagecontainer']/section/ul/li[1]/a"));
String linkLocation = link.getAttribute("href");
return linkLocation;
}
public void actionPerformed(ActionEvent e)
{
desk.browse(new URI(LinkLocation()));
}
关于java - 将以前使用的字符串导入到新方法中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251619/