Selenium webdriver Selenium程序选择并输入文本框中列出的数据

Selenium webdriver Selenium程序选择并输入文本框中列出的数据,selenium-webdriver,Selenium Webdriver,Selenium计划通过amazon网站上的amazon pay预订公共汽车票。 登录并导航到amazon pay,然后单击“旅行票、生活方式优惠”类别下的“公共汽车票”按钮 但无法在“输入源城市”文本框中输入州名称 代码: 问题是什么?您的xpath中有反斜杠表示ID值,已将其删除,它应该可以工作:/*[@ID=“bs_lp_route”]/div[1]/div/div/div/div/div或者您也可以使用此xpath:/*[text()='Enter source city'] impor

Selenium计划通过amazon网站上的amazon pay预订公共汽车票。 登录并导航到amazon pay,然后单击“旅行票、生活方式优惠”类别下的“公共汽车票”按钮 但无法在“输入源城市”文本框中输入州名称

代码:


问题是什么?您的xpath中有反斜杠表示ID值,已将其删除,它应该可以工作:
/*[@ID=“bs_lp_route”]/div[1]/div/div/div/div/div
或者您也可以使用此xpath:
/*[text()='Enter source city']
import org.openqa.selenium.By;`
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 Ticket {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");
        
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.amazon.in/");
        
        driver.findElement(By.id("nav-link-accountList")).click();
        driver.findElement(By.id("ap_email")).sendKeys("amazon login id");
        driver.findElement(By.id("continue")).click();
        driver.findElement(By.id("ap_password")).sendKeys("amazon password");
        driver.findElement(By.id("signInSubmit")).click();
        driver.findElement(By.xpath("//*[@id='nav-xshop']/a[1]")).click();
      
        WebDriverWait wait = new WebDriverWait(driver,60);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='Buses']"))).click();
        System.out.println("Page loaded");
       driver.findElement(By.xpath("//*[@id=\"bs_lp_route\"]/div[1]/div/div/div/div/div")).click();
       Thread.sleep(5000);
     driver.findElement(By.xpath("/[@id=\"bs_lp_route\"]/div[1]/div/div/div/div/div")).sendKeys("Delhi");