Selenium Testing - 无法从日历列表中选择值

时间:2017-04-16 07:19:23

标签: java selenium testing selenium-webdriver

我无法从日历列表中选择日期值。所有其他测试都有效。

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class ch1 {
    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
         System.setProperty("webdriver.chrome.driver", "C://testing/chromedriver_win32/chromedriver.exe");
         WebDriver driver = new ChromeDriver();
         driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
         driver.get("https://www.via.com");
         try {
             driver.findElement(By.xpath("//div[@class='wzrk-button-container']/button[1]")).click();
         }
         finally {
             driver.findElement(By.xpath("//div[@class='element relElements airportElements']/input[1]")).sendKeys("BLR");
             driver.findElement(By.xpath("//div[@class='calendar-icon']")).click();
             Select s = new Select(driver.findElement(By.xpath("//*[@id='depart-cal']/div[3]")));
             s.selectByValue("19");

             driver.wait(5000);
        }
    }
}

正在输入文本并且日历正在打开,但日期未被选中。

1 个答案:

答案 0 :(得分:1)

这里的日历不是一个select元素,它是一个div元素。所以选择在这种情况下不会工作。

尝试以下代码:

<?php

require('dbConnect.php');

$CheckContact = $_POST['phonenumber'];
$sql = "SELECT * FROM user WHERE username = '$CheckContact'";
$result = mysqli_query($con, $sql);
$check = mysqli_fetch_array($result);
//if $CheckContact is in the user table...
if(isset($check)) {

    echo 'success.' . "<br>";

    // get the associated rows of $CheckContact
       $row = mysqli_fetch_assoc($result);
    // get the associated user_id in that row

       $contact_id = $row["user_id"];
       echo "the user id is ", $contact_id;

} 
//if $CheckContact is NOT in the user table...
else {

    echo 'failure';
    }

?>

让我知道它是否适合你。