当我运行此脚本时,会出现错误消息。
元素信息:{Using = xpath, 值= HTML /体/表/ tbody的/ TR [2] / TD [1] / DIV / DIV [1] /字段集/ DIV / DIV [17]}
我尝试下面提到的代码,但它对我没用。
fd.findElement(By.xpath("html/body/table/tbody/tr[2]/td[1]/div/div[1]/fieldset/div/div[17]")).click();
这是开发人员代码。
<div id="ui-id-5" class="ui-accordion-header ui-state-default ui-corner-all ui-accordion-icons ui-state-hover" role="tab" aria-controls="ui-id-6" aria-selected="false" aria-expanded="false" tabindex="-1">
<span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"/>
Education Institution
</div>
答案 0 :(得分:0)
一个好的元素定位器:
不是硒代码问题,您定义的定位器问题。试试这段代码
fd.findElement(By.xpath("//div[@id='ui-id-5']")).click();
关注this什么是'好'元素定位器。
答案 1 :(得分:0)
请尝试以下代码:
driver.get("http://117.247.65.9/wb_isgp_test/secured/home.jsp");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.id("mapUp")).click();
WebDriverWait wait = new WebDriverWait(driver, 25);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.cssSelector("input[id='gp1']"))));
driver.findElement(By.cssSelector("input[id='gp1']")).click();
Thread.sleep(5000);
driver.findElement(By.cssSelector("input[value='Whizmap']")).click();
Thread.sleep(8000);
String childWindow = (String) driver.getWindowHandles().toArray()[1];
driver.switchTo().window(childWindow);
System.out.println("Switch to new tab.");
String text = driver.findElement(By.xpath("//div[@id='ui-id-5']")).getText();
System.out.println(text);
WebDriverWait wait1 = new WebDriverWait(driver, 25);
wait1.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='ui-id-5']"))));
driver.findElement(By.xpath("//div[@id='ui-id-5']")).click();