线程“main”org.openqa.selenium. Javascript异常:javascript错误:无法读取null的属性(阅读“样式”)

pgccezyw  于 2023-04-21  发布在  Java
关注(0)|答案(1)|浏览(237)

我正在尝试使用Javascript Executor类中有一个元素has**style=“display:none”**但我得到标题中提到的错误。我无法执行sendKeys到文本框

void clickonLaterSignup()
   {
       WebElement m=driver.findElement(By.xpath("//a[@id='later']"));
       WebElement n=driver.findElement(By.xpath("//span[@class='user-signin']"));
       WebElement n1=driver.findElement(By.xpath("//button[@class='black-btn-skew btn']"));

        m.click();
        n.click();
        n1.click();
       WebDriverWait wait=new WebDriverWait(driver, Duration.ofSeconds(100));
       wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='pf-widget-content']")));
       driver.findElement(By.xpath("//button[@class='pf-widget-close']")).click();

    }
    void SignIn()
    {
        WebElement signInhover= driver.findElement(By.xpath("//span[@class='user-signin']"));
        signInhover.click();
        WebElement ele= driver.findElement(By.xpath("//div[@class='red-btn-skew btn']"));
        ele.click();
        //WebElement fname= driver.findElement(By.xpath("//input[@class='gigya-input-text first-capitalize']"));
        //fname.sendKeys("Harshit");
        ((JavascriptExecutor) driver).executeScript("document.getElementById('gigya-textbox-109721930953108590').style.display='block';");
        WebElement sname= driver.findElement(By.xpath("//input[@name='profile.lastName']"));
        sname.sendKeys("Verma");
        WebElement email=driver.findElement(By.xpath("//input[@name='email']"));
        email.sendKeys("harshitverma742");

    }

    public static void main(String args[])
    {
        System.setProperty("webdriver.chrome.driver","C://Users//vermahg//Downloads//chromedriver_win32 (4)//chromedriver.exe");
        driver= new ChromeDriver();
        driver.get("https://www.manutd.com/");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Main m1=new Main();
        m1.clickonLaterSignup();
        m1.SignIn();

    }
}
agxfikkp

agxfikkp1#

你不需要修改INPUTs等的可见性来填写表单。下面的代码执行以下步骤:
1.点击登录
1.点击注册按钮
1.填写了大部分表格
我省略了“保持更新”的收音机切换和最后的“联合签名”按钮点击。

driver = new ChromeDriver();
driver.manage().window().maximize();
String url = "https://www.manutd.com";
driver.get(url);

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

// click to Sign Up
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("gigyalogin"))).click();
driver.findElement(By.cssSelector("li.signUp_btn")).click();

// fill in form
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='profile.firstName']"))).sendKeys("FirstName");
driver.findElement(By.cssSelector("input[name='profile.lastName']")).sendKeys("LastName");
driver.findElement(By.cssSelector("input[name='email']")).sendKeys("email");
driver.findElement(By.cssSelector("input[name='password']")).sendKeys("Passw0rd");
driver.findElement(By.cssSelector("input[name='passwordRetype']")).sendKeys("Passw0rd");
new Select(driver.findElement(By.cssSelector("select[name='profile.country']"))).selectByVisibleText("United Kingdom");
new Select(driver.findElement(By.cssSelector("select[name='profile.birthDay']"))).selectByVisibleText("01");
new Select(driver.findElement(By.cssSelector("select[name='profile.birthMonth']"))).selectByVisibleText("01");
new Select(driver.findElement(By.cssSelector("select[name='profile.birthYear']"))).selectByVisibleText("2000");

相关问题