I am using two different ways to access a web element with Selenium webdriver (JavaScript) .
The first way uses a number indicating third div
element in the parent div
. The code is like this:
driver.findElement(By.xpath("//div[@id='sld-layer-container']/div/div/ul/li[2]/div/div[2]/div/div[3]/select/option[2]")).click();
This code doesn't work. It returns error: ElementNotVisibleError: element not visible: Element is not currently visible and may not be manipulated
The second way uses class to identify the specific div
in parent div
. Code is like this:
driver.findElement(By.xpath("//div[@id='sld-layer-container']/div/div/ul/li[2]/div/div[2]/div/div[@class = 'col-md-5']/select/option[2]")).click();
As you can see, the only difference is the identifier of last div element in xPath string. They should indicate the same thing. Magically the second one works but not the first one.
Here is a screenshot of css elements. The div
highlighted is what I am trying to locate.
Can anyone help me with this?
Update 1:
As @Mahipal and @iamkenos required, I expended the div
and now it is showing select
and option
. I thought the issue was only caused by not being able to locate the div
but it seems not. Please help further.
you can try as below:
Select select = new Select (driver.findElement(By.xpath("//div[@id='sld-layer-container']/div/div/ul/li[2]/div/div[2]/div/div[3]/select")));
select.selectByVisibleText("PROJECT_VALUE");
您也可以在xpath下面尝试...
//div[@id='featureClassList']//div[@class='col-md-5']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.