【问题标题】:i'm tring to automate target.com in selenium using java我正在尝试使用 java 在 selenium 中自动化 target.com
【发布时间】:2021-09-21 03:26:47
【问题描述】:

1.错误在第 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\"]"));
}

【问题讨论】:

  • 显而易见的事情,但您确认 document.getElementById('...') 返回元素了吗?

标签: java selenium maven automation


【解决方案1】:

在firefox的网址栏中输入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");

【讨论】:

    【解决方案2】:

    菜单仅在将鼠标悬停在登录元素上时出现。
    尝试悬停并单击登录菜单,然后移动到登录 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
    至于

    找不到配置文件目录。 console.warn: SearchSettings: "get: 不存在设置文件,新配置文件?

    错误见this和其他答案here
    首先验证那里提到的浏览器配置文件。

    【讨论】:

    • The menu appears only when hovering over sign in element. - 没有 HTML 或页面 URL 你怎么知道这是一个悬停问题
    • 他提到他正在尝试自动化 target.com
    • 同样的错误JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory. console.warn: SearchSettings: "get: No settings file exists, new profile?
    • @M.Mobark 你之前没有提到这个错误。我试试看是什么原因造成的。
    • @Prophet :好吧,我没看标题。
    猜你喜欢
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    相关资源
    最近更新 更多