私は公共の場所で働いています:
http://preview.harriscountyfws.org/ElementNotVisible例外セレンwebdriverをJavaの
、以下に示すロジックはElementNotVisibleExceptionに遭遇しました。 しかし、 "//"で始まる2行のコメントを外してそのコードの上の2行をコメントアウトすると、コードはうまく動作します(しかし、これは必要なものとは別のドロップダウンです)。
私は困惑しています。 「降雨の最後の」ドロップダウンから選択できます。 しかし、まったく同じ方法を使用して、「場所によるGage」ドロップダウンから選択することはできません。
[Gage by Location]ドロップダウンリストから選択するにはどうすればよいですか?
package sdfwe.sdwd.qsde;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Gfgsdrfffde {
public static void main(String[] args) {
System.out.println("Running Tests....");
// Optional, if not specified, WebDriver will search your path for chromedriver.
System.setProperty("webdriver.chrome.driver", "C:\\ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://preview.harriscountyfws.org/");
driver.manage().window().maximize();
WebElement we;
String searchText;
WebElement dropdown;
//if you comment out the next two lines after these comments and
// uncomment out the commented lines below, the code works
searchText = "110:A100_110 Clear Creek @45";
dropdown = driver.findElements(By.cssSelector("span.k-widget")).get(3);
// searchText = "24 Hours";
// dropdown = driver.findElements(By.cssSelector("span.k-widget")).get(1);
System.out.println("Attempting Dropdown Click....");
dropdown.click();
System.out.println("Finished running Dropdown Click....");
Sleep(4);
//Select dd2 = new Select(driver.findElement(By.id("ddlTimeSpan")));
//dd2.selectByVisibleText(searchText);
we = driver.findElement(By.xpath("//li[text()='" + searchText + "']"));
if (we != null) {
we.click();
}
System.out.println("Finished Selecting Dropdown....");
//driver.quit();
}
public static void Sleep(int i)
{
try { Thread.sleep(i * 300); }
catch(InterruptedException ie) { System.out.println("Unexpected error in sleep"); }
}
}
インデックスで選択することは、常に信頼性が低くなります。実際に 'driver.findElements(By.cssSelector(" span.k-widget "))'が返され、正しい要素を選択したかどうか、または目的の要素を直接選択しないことを確認する必要があります。 'driver.findElement(By.xpath(" span(text))= '(Select Gage)'] "));' –