在这里,我想选择4月的返回日期12。我尝试使用其他自定义的xpath和CSS,但无法找到该元素:
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Make_my_trip {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "F:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.makemytrip.com/");
// Selecting Return date
driver.findElement(By.id("hp-widget__return")).click();
//WebDriverWait ws = new WebDriverWait(driver, 10);
//ws.until(ExpectedConditions.presenceOfElementLocated(By.id("dp1551508380301")));
Thread.sleep(2000);;
while (!driver.findElement(By.xpath("//span[@class ='ui-datepicker-month']")).getText().contains("April")) {
System.out.println("Return date selected ");
driver.findElement(By.xpath(
"div[@id='dp1551508898872']//span[@class='ui-icon ui-icon-circle-triangle-e'][contains(text(),'Next')"))
.click();
}
List<WebElement> returndate = driver.findElements(By.xpath("//a[@class ='ui-state-default']"));
int count = returndate.size();
for (int j = 0; j < count; j++) {
String returndatetext = driver.findElements(By.xpath("//a[@class ='ui-state-default']")).get(i).getText();
if (returndatetext.equalsIgnoreCase("12")) {
driver.findElements(By.xpath("//a[@class ='ui-state-default']")).get(i).click();
break;
}
}
}
PS:
Thread.sleep(1000)
。//div[@class='ui-datepicker-group ui-datepicker-group-last']/div/a/span[contains(text(),'Next' )][1]
org.openqa.selenium.ElementNotVisibleException:元素不可见 答案 0 :(得分:0)
“元素不可见”。我也有这个错误。这意味着您的可搜索元素在当前快照中不可见。您应该专注于该元素或向下滚动直到该元素出现在快照中