【问题标题】:Selenium: Cannot enter username in https://www.phptravels.net/adminSelenium:无法在 https://www.phptravels.net/admin 中输入用户名
【发布时间】:2021-09-15 07:10:21
【问题描述】:

我尝试在 https://www.phptravels.net/admin 中练习 selenium 自动化,但我无法输入用户名。

private By username = By.xpath("//input[@type='text'][@name='email']");

Actions inputAct = new Actions(mngr.getDriver());
inputAct.click().sendKeys("admin@phptravels.com").perform();         

mngr.getDriver().findElement(page.getUsername()).sendKeys("admin@phptravels.com");

我在开发人员工具中搜索 xpath ahs 唯一元素。为什么无法输入用户名。谢谢。

【问题讨论】:

  • 为什么没有人愿意帮助我?
  • 页面说:Selenium, Bots, or any automated softwares are not allowed to test here!
  • 你试过让硒无法检测吗?

标签: java cucumber extentreports


【解决方案1】:

你需要绕过硒的检测方法。

ChromeOptions options = new ChromeOptions();
IWebDriver driver;
options.AddArguments("--disable-notifications");
options.AddArguments("--no-zygote");
options.AddArguments("--disable-accelerated-2d-canvas");
options.AddArguments("--disable-setuid-sandbox");
options.AddArguments("--no-first-run");
options.AddArguments("--disable-2d-canvas-clip-aa");
options.AddArgument($"--user-agent={UA}");
options.AddArguments("start-maximized");
options.AddArguments("--blink-settings=imagesEnabled=false");
options.AddUserProfilePreference("profile.default_content_setting_values.css", 2);
options.AddArguments("--disable-gpu");
options.AddArgument("ignore-certificate-errors");
options.AddExcludedArguments(new List<string>() { "enable-automation" });
options.AddArguments("--disable-blink-features=AutomationControlled");
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("Object.defineProperty(navigator, 'webdriver', {get: () => false})");
driver.Navigate().GoToUrl("https://www.phptravels.net/admin");
new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div[2]/form[1]/div[1]/label[1]/input"))).SendKeys("jdhfshshdf");
                

【讨论】:

    【解决方案2】:

    这对我有用:

        RemoteWebDriver driver = new FirefoxDriver();
        driver.get("https://www.phptravels.net/admin");
    
        WebElement emailInput = driver.findElement(new By.ByXPath("//input[@type='text'][@name='email']"));
    
        emailInput.sendKeys("TEST TEST TEST");
    
        driver.close();
    

    【讨论】:

      猜你喜欢
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 2020-01-21
      • 1970-01-01
      相关资源
      最近更新 更多