Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 异常org.openqa.selenium.ElementNotVisibleException:…元素不可见_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 异常org.openqa.selenium.ElementNotVisibleException:…元素不可见

Java 异常org.openqa.selenium.ElementNotVisibleException:…元素不可见,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,正在尝试选择单选按钮,但正在获取ElementNotVisibleException:exception。请参阅下面的代码 public class Automatecheckbox { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub System.setProperty("webdriver.c

正在尝试选择单选按钮,但正在获取ElementNotVisibleException:exception。请参阅下面的代码

public class Automatecheckbox {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver", "G:/chromedriver/chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        driver.manage().window().maximize();

        driver.get("http://www.facebook.com");

       WebElement male_radio_button=driver.findElement(By.xpath(".//*[@id='u_0_c']"));


       boolean status=male_radio_button.isDisplayed();

       System.out.println("Male radio button is Displayed >>"+status);

        boolean enabled_status=male_radio_button.isEnabled();

        System.out.println("Male radio button is Enabled >>"+enabled_status);

      boolean selected_status=male_radio_button.isSelected();

        System.out.println("Male radio button is Selected >>"+selected_status);

        Thread.sleep(1000);

        male_radio_button.click();

      boolean selected_status_new=male_radio_button.isSelected();

        System.out.println("Male radio button is Selected >>"+selected_status_new);

    }

}

尝试使用以下代码查找元素:

WebElement male_radio_button = driver.findElement(By.xpath("//input[@id='u_0_c']"));

希望它能起作用

使用显式wait WebDriverWait让WebElement在对其执行任何操作之前加载。在本例中,WebDriverWait对象在调用ChromeDriver后立即初始化

使用以下代码:

driver.findElement(By.xpath("//input[@value='2']")).click();
您在哪一行看到ElementNotVisibleException?您能用整个错误堆栈跟踪更新问题吗?
driver.findElement(By.xpath("//input[@value='2']")).click();