为什么这段代码会从我项目中随机的其他代码中抛出输出?我怎样才能解决这个问题?
问题描述:
我是Java的新手,我可能在代码中弄乱了一些东西。但这里有什么问题?我正在尝试为我必须测试的主页中的元素创建对象。
I am new to Java and I might have messed up something in the code. But what is wrong here? I am trying to create objects for the elements in the home page which I have to test.
package pageObjects;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class HomePage {
private static WebElement element;
public static void main(String args[], WebDriver driver){
HomePage hp = new HomePage();
hp.SignInButton(driver);
hp.ImageButton(driver);
System.out.println("Yup");
}
public WebElement SignInButton(WebDriver driver){
element = driver.findElement(By.linkText("Sign In"));
System.out.println("Yeua");
return element;
}
public WebElement ImageButton(WebDriver driver){
return element = driver.findElement(By.linkText("Images"));
}
}
答
根据您使用的IDE,您必须检查运行配置并查看正在执行的IDE。
Depending on the IDE you are using, you have to check the run configuration and see, which one is being executed.
如果您不这样做有一个有效的 main()
开始,大多数IDE将使用有效的 main()$ c $执行你开始的最后一个文件c>。
If you do not have a valid main()
to start with, most IDEs will execute the last file that you started with a valid main()
.
你的 main()
有多个参数 public static void main( String args [],WebDriver驱动程序)
删除 WebDriver驱动程序