我想点击此页面中的搜索区域 http://test1.absofttrainings.com
代码:
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class FindProduct {
@Test
public void findProduct(){
WebDriver driver= new FirefoxDriver();
driver.get("http://test1.absofttrainings.com/");
WebElement search_link=driver.findElement(By.xpath("//span[@id='et_search_icon']"));
Actions action= new Actions(driver);
action.moveToElement(search_link).build().perform();
driver.findElement(By.xpath("//span[@id='et_search_icon']")).click();
}
}
我收到Element Not visible异常。我曾尝试使用implicitlyWait,但这也无效。欢迎您的建议/建议。
答案 0 :(得分:0)
尝试使用
driver.findElement(By.id("et_top_search")).click();
或使用JS
((JavascriptExecutor)driver).executeScript("document.getElementById('et_search_icon').click();");
请查看此链接How to force Selenium WebDriver to click on element which is not currently visible?
某些规则基于“Selenium”确定元素是否可见(确保您查看计算样式):