我正在尝试使用css选择器定位元素,但是会抛出
错误说元素很难处理,供参考,这是我的代码
System.setProperty("webdriver.chrome.driver","/home/ibrahim/eclipse-workspace/chromedriver"); WebDriver dr = new ChromeDriver(); dr.get("http://52.66.136.77:3003/"); dr.manage().window().maximize(); dr.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS ); System.out.println("passed sleeping"); dr.findElement(By.xpath("//input[@id='name']")).sendKeys("unknown"); System.out.println("passed finding elements"); dr.findElement(By.xpath("//input[@id='password']")).sendKeys("1234"); dr.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS ); dr.findElement(By.xpath("//a[text()='Login']")).click();
dr.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS );
dr.findElement(By.xpath("(//img)[@src='/images/home/dataset.png'][2]")).click();
System.out.println("image printed"); dr.findElement(By.xpath("//*[@id=\"tl-
app\"]/div[2]/div[3]/div[2]/div/div[2]/div")).click();
System.out.println("element found"); dr.findElement(By.xpath("//button[@type='button']")).click(); System.out.println("found browse button"); //String arg2 = args[1]; StringSelection stringselection = new StringSelection("/home/ibrahim/Datasets/MiniDataSet Latest/Interchange_Mini.csv"); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, null); Robot robot = new Robot(); robot.setAutoDelay(200); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_L); //robot.setAutoDelay(2000); robot.keyRelease(KeyEvent.VK_L); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); //Actions action = new Actions(dr); Thread.sleep(500); WebElement cl = dr.findElement(By.xpath("//a[text()='Upload']")); cl.click();
System.out.println("upload worked"); WebDriverWait wait = new WebDriverWait (dr,25); WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Create new dataset']"))); element.click(); System.out.println("create metadata worked"); try { dr.findElement(By.xpath("//a[text()='OK']")).click(); } catch (NoSuchElementException e) { System.out.println("pls ignore this"+e.getMessage()); } WebElement element2 = dr.findElement(By.xpath("//a[text()='Create metadata']")); WebElement element3 = dr.findElement(By.xpath("//div[text()='Dataset was created successfully!']")); element3.click(); element2.click(); System.out.println("metadata clicked"); dr.findElement(By.xpath("//input[@placeholder='Project']")).sendKeys("autotest"); dr.findElement(By.xpath("//input[@placeholder='Title']")).sendKeys("autotest"); WebElement element4 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Continue']"))); element4.click(); dr.findElement(By.xpath("//span[@class='glyphicon glyphicon glyphicon-text-background']")).click(); System.out.println("auto populate"); dr.findElement(By.xpath("//span[@class='glyphicon glyphicon glyphicon-stats']")).click(); System.out.println("open explorer"); dr.findElement(By.xpath("(//a)[@data-tie='motifSelect'][1]")).click(); System.out.println("select motif"); WebElement graph = dr.findElement(By.cssSelector("#tl-app > div.app-container > div.column-layout > div.card-layout > div > div > div > div.ts-panel > svg > g:nth-child(3) > g.brushes > g > rect.background")); graph.click();
我在最后一个webelement
图中发现了此错误。
我得到的错误树是:
线程“主”中的异常org.openqa.selenium.ElementNotVisibleException:元素不可交互 (会议信息:chrome = 71.0.3578.98) (驱动程序信息:chromedriver = 2.45.615279(12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform = Linux 4.15.0-42-generic x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:0毫秒 内部版本信息:版本:'3.141.59',修订版本:'e82be7d358',时间:'2018-11-14T08:25:48' 系统信息:主机:'as005',ip:'127.0.1.1',操作系统名称:'Linux',os.arch:'amd64',os.version:'4.15.0-42-generic',java.version :'1.8.0_191' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能{acceptInsecureCerts:false,acceptSslCerts:false,applicationCacheEnabled:false,browserConnectionEnabled:false,browserName:chrome,chrome:{chromedriverVersion:2.45.615279(12b89733300bd2 ...,userDataDir:/tmp/.org.chromium.Chromium ... },cssSelectorsEnabled:true,databaseEnabled:false,goog:chromeOptions:{debuggerAddress:localhost:42395},handlesAlerts:true,hasTouchScreen:false,javascriptEnabled:true,locationContextEnabled:true,mobileEmulationEnabled:false,nativeEvents:true,networkConnectionEnabled:false, pageLoadStrategy:正常,平台:LINUX,平台名称:LINUX,代理:Proxy(),可旋转:false,setWindowRect:true,strictFileInteractability:false,takesHeapSnapshot:true,takesScreenshot:true,超时:{隐式:0,pageLoad:300000,脚本:30000},unexpantedAlertBehaviour:忽略,unhandledPromptBehavior:忽略,版本:71.0.3578.98,webStorageEnabled:true} 会话ID:80fab6077716c83f2b8926a5b67c81fa 在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)处 在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) 在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) 在org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) 在org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80) 在org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44) 在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) 在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) 在org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285) 在org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84) 在Trendalyze_file_upload1.FirstTestCase.main(FirstTestCase.java:91)