2017-05-17 10 views
0

Irctcのbook nowボタンはクリックできません。 示されているエラーは、対話できない要素です。 私は使用しようとしましたクリックしてIRCTCに表示されないボタン、セレンを使用

wait.until(ExpectedConditions.elementToBeClickable(By.xpath(""))); 

まだゲインがありません。

FirefoxOptions options = new FirefoxOptions(); 
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine 

WebDriver driver = new FirefoxDriver(options); 

WebDriverWait wait = new WebDriverWait(driver, 10); 

driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); 

driver.get("http://www.irctc.co.in");//It will open the website 

driver.manage().window().maximize();//It will maximize the window 

Thread.sleep(5000);//For Entering the Captcha before 5sec 

driver.findElement(By.xpath("//input[@id='usernameId']")).sendKeys("");//enter username 

driver.findElement(By.xpath("//input[@class='loginPassword']")).sendKeys("");//enter password 

driver.findElement(By.xpath("//input[@id='loginbutton']")).click();//clicks on sign in 

Thread.sleep(2000); 

driver.findElement(By.xpath("//input[@id='jpform:fromStation']")).sendKeys("H NIZAMUDDIN - NZM");//origin station 


driver.findElement(By.xpath("//input[@id='jpform:toStation']")).sendKeys("KOTA JN - KOTA");//destination station 


driver.findElement(By.xpath("//input[@id='jpform:journeyDateInputDate']")).sendKeys("18-05-2017");//Date Of Journey 

Thread.sleep(2000); 

driver.findElement(By.xpath("//input[@id='jpform:jpsubmit']")).click();//Clicks to find the trains 

Thread.sleep(2000); 

driver.findElement(By.xpath("//a[@id='cllink-13237-CC-1']")).click();//Clicks the class of train to find available seats 

Thread.sleep(5000); 

driver.findElement(By.xpath("//a[@id='13237-3A-GN-0']")).click();//For clicking on Book Now, but is not functioning. 
+0

IDが 'cllink-13237-CC-1'の要素がページに存在しません。どの列車を選択しようとしましたか? –

+0

私がコードで述べた列車番号は間違っています。それ以外の場合、そのコード行はFirefoxブラウザで正常に実行されていました。 –

答えて

0

注:私はIRCTCの自動化を奨励しておりません。これはちょうど正しい方向にOPを導くことです。自己責任。

私はChromeDriverを使用していますが、任意のドライバを使用できますが、Javascriptをサポートしていることを確認してください。コードはこちら

import org.openqa.selenium.By; 
import org.openqa.selenium.JavascriptExecutor; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.chrome.ChromeOptions; 
import org.openqa.selenium.remote.DesiredCapabilities; 

class Main{ 
    public static void main(String args[])throws InterruptedException{ 
     System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shash\\Desktop\\chromedriver.exe"); 
     ChromeOptions options = new ChromeOptions(); 
     options.addArguments("window-size=1024,768"); 

     DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
     capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
     WebDriver driver = new ChromeDriver(capabilities); 

     driver.get("http://www.irctc.co.in");//It will open the website 
     Thread.sleep(5000);//For Entering the Captcha before 5sec 

     driver.findElement(By.xpath("//input[@id='usernameId']")).sendKeys("");//enter username 

     driver.findElement(By.xpath("//input[@class='loginPassword']")).sendKeys("");//enter password 

     driver.findElement(By.xpath("//input[@id='loginbutton']")).click();//clicks on sign in 

     Thread.sleep(2000); 

     driver.findElement(By.xpath("//input[@id='jpform:fromStation']")).sendKeys("H NIZAMUDDIN - NZM");//origin station 


     driver.findElement(By.xpath("//input[@id='jpform:toStation']")).sendKeys("KOTA JN - KOTA");//destination station 


     driver.findElement(By.xpath("//input[@id='jpform:journeyDateInputDate']")).sendKeys("18-05-2017");//Date Of Journey 

     driver.findElement(By.xpath("//input[@id='jpform:jpsubmit']")).click();//Clicks to find the trains 
     driver.findElement(By.xpath("//a[@id='cllink-12060-CC-0']")).click();//Clicks the class of train to find available seats 
     Thread.sleep(3000); 
     if (driver instanceof JavascriptExecutor) { 
      ((JavascriptExecutor) driver) 
       .executeScript("document.getElementById(\"12060-CC-GN-0\").click()"); 
     } 
    } 
} 

コードにはいくつかの問題があります。最初に、ID cllink-13237-CC-1の要素が存在しませんでした。あなたは要素の正確なIDを取得することを確認してください。 IRCTCでは右クリックが許可されていないので、Ctrl + Shift + を使用してソースを表示することができます。

第2に、Book Now要素が隠されていたため、Javascriptをクリックして使用しました。

+0

解決していただきありがとうございます。私はどこで待つべきか、どこでそれを避けるべきかを提案できますか? –

+0

@SushantKumarあなたは 'Thread.sleep'をすべて削除することができます。 captchaとJavaScript Executorの前に保管してください。私はIRCTCに精通していないので、再度実験しなければならないかもしれません。 –

関連する問題