如何在span类中使用 xpath 。 (硒)
<span class="custom-auto-complete_pic"
onclick="supplierParmsCreate.browseSpSupplier();">
</span>
我已经尝试过以下内容并且无法正常工作
WebElement selectVendor =
(new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[@class='custom-auto-complete_pic']")));
selectVendor.click();
获取响应
线程“main”中的异常org.openqa.selenium.ElementNotVisibleException:元素不可见 (会话信息:chrome = 43.0.2357.81) (驱动程序信息:chromedriver = 2.15.322448(52179c1b310fec1797c81ea9a20326839860b7d3),platform = Windows NT 6.1 SP1 x86)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:466毫秒 构建信息:版本:'2.45.0',修订版:'32a636c',时间:'2015-03-05 22:01:35' 系统信息:主机:'C9100970EE83EA7',ip:'172.22.51.106',os.name:'Windows 7',os.arch:'x86',os.version:'6.1',java.version:'1.7.0_40 “ 会话ID:06156aab2bfcf3027acde966a4c24d73 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能[{platform = XP,acceptSslCerts = true,javascriptEnabled = true,browserName = chrome,chrome = {userDataDir = C:\ Users \ nxs8519 \ AppData \ Local \ Temp \ 2 \ scoped_dir17496_10555},rotate = false,locationContextEnabled = true, mobileEmulationEnabled = false,version = 43.0.2357.81,takesHeapSnapshot = true,cssSelectorsEnabled = true,databaseEnabled = false,handlesAlerts = true,browserConnectionEnabled = false,webStorageEnabled = true,nativeEvents = true,applicationCacheEnabled = false,takesScreenshot = true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) 在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) 在org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268) 在org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79) 在com.homedepot.pomt.testSuite.THDParms.createTHDParms(THDParms.java:63) 在com.homedepot.pomt.Util.Login.main(Login.java:53)
答案 0 :(得分:1)
试试这个。它应该更具体
WebElement selectVendor =
(new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[@onclick='supplierParmsCreate.browseSpSupplier();']")));
selectVendor.click();