我正在尝试使用 java 在 selenium 中自动化 target.com
i'm tring to automate target.com in selenium using java
1.error 第 3 行
我无法访问注册 btn(我尝试使用 ID、XPath、名称和选择器,但不起作用!)
@Test
public void registration() throws InterruptedException {
mydriver.findElement(By.xpath("/html/body/div[1]/div/div[3]/div[2]/nav/a[7]/span[4]")).click(); // pass
Thread.sleep(2000);// just for test
mydriver.findElement(By.id("accountNav-signIn")).click(); // fail
// mydriver.findElement(By.name("usernamecreateaccount")).sendKeys("test@gmail.com");
// mydriver.findElement(By.name("firstnamecreateaccount")).sendKeys("mohammed");
// mydriver.findElement(By.name("lastnamecreateaccount")).sendKeys("mobark");
// mydriver.findElement(By.name("passwordcreateaccount")).sendKeys("Pass@1234");
// WebElement submit_btn = mydriver.findElement(By.xpath("//*[@id=\"createAccount\"]"));
}
只有将鼠标悬停在登录元素上时才会显示菜单。
尝试将鼠标悬停并单击登录菜单,然后移动到登录 li
并单击 Actions
。
像这样:
Actions action = new Actions(mydriver);
WebElement webElement = mydriver.findElement(By.xpath("//nav[@id='headerMain']//a[@id='account']"));
WebElement webElement1 = mydriver.findElement(By.xpath("//li[@id='accountNav-signIn']"));
action.moveToElement(webElement).click(webElement).moveToElement(webElement1).click(webElement1).build().perform();
UPD
约
Can't find profile directory. console.warn: SearchSettings: "get: No settings file exists, new profile?
错误见this and other answers here
首先按照此处所述验证您的浏览器配置文件。
在 firefox 的 URL 栏中输入 about:profiles
并检查是否
默认配置文件存在于该位置,如果它不存在
创建一个并提供默认或所需位置。
点击 Create a new profile
-> Continue
--> Enter the profile name
-> click Done
Try to access the profile created with the below lines of code
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("ffProfile");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(ffProfile);
WebDriver driver = new FirefoxDriver(option);
driver.get("https://www.target.com");
@Test
public void registration() throws InterruptedException {
mydriver.findElement(By.xpath("/html/body/div[1]/div/div[3]/div[2]/nav/a[7]/span[4]")).click(); // pass
Thread.sleep(2000);// just for test
mydriver.findElement(By.id("accountNav-signIn")).click(); // fail
// mydriver.findElement(By.name("usernamecreateaccount")).sendKeys("test@gmail.com");
// mydriver.findElement(By.name("firstnamecreateaccount")).sendKeys("mohammed");
// mydriver.findElement(By.name("lastnamecreateaccount")).sendKeys("mobark");
// mydriver.findElement(By.name("passwordcreateaccount")).sendKeys("Pass@1234");
// WebElement submit_btn = mydriver.findElement(By.xpath("//*[@id=\"createAccount\"]"));
}
只有将鼠标悬停在登录元素上时才会显示菜单。
尝试将鼠标悬停并单击登录菜单,然后移动到登录 li
并单击 Actions
。
像这样:
Actions action = new Actions(mydriver);
WebElement webElement = mydriver.findElement(By.xpath("//nav[@id='headerMain']//a[@id='account']"));
WebElement webElement1 = mydriver.findElement(By.xpath("//li[@id='accountNav-signIn']"));
action.moveToElement(webElement).click(webElement).moveToElement(webElement1).click(webElement1).build().perform();
UPD
约
Can't find profile directory. console.warn: SearchSettings: "get: No settings file exists, new profile?
错误见this and other answers here
首先按照此处所述验证您的浏览器配置文件。
在 firefox 的 URL 栏中输入 about:profiles
并检查是否
默认配置文件存在于该位置,如果它不存在
创建一个并提供默认或所需位置。
点击 Create a new profile
-> Continue
--> Enter the profile name
-> click Done
Try to access the profile created with the below lines of code
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("ffProfile");
FirefoxOptions option = new FirefoxOptions();
option.setProfile(ffProfile);
WebDriver driver = new FirefoxDriver(option);
driver.get("https://www.target.com");