0
votes

For practice sake, I'm writing test cases for irctc website, there I need to enter from station place and then respective stations with that code will be displayed as bootstrap dropdown and now i have to select one among them and click enter. Unfortunately there is no enter/submit button for from and to text field, please help me to continue with this test case

Here is my code

IWebElement Fromstn = driver.FindElement(By.XPath("//*[@id='divMain']/div/app-main-page/div/div/div[1]/div[1]/div[1]/app-jp-input/div/form/div[2]/div[1]/div[1]/span/i"));
                 Thread.Sleep(2000);
                  Fromstn.SendKeys("MAQ");
                  Fromstn.Click();
 ```**OR**

Actions builder = new Actions(driver); Actions hover = builder.MoveToElement(driver.FindElement(By.XPath("//*[@id='origin']"))); hover.Build().Perform(); Thread.Sleep(2000); hover.SendKeys("MAQ"); hover.Click();

3
Have you tried any code? Any errors?itronic1990
Yes, If I give sendKeys or Click on the WebElement, It throws an exception that element not interactableAishwarya Mohan
Please share the xpath you have trieditronic1990
I tried with Actions aswel, Actions builder = new Actions(driver); Actions hover = builder.MoveToElement(driver.FindElement(By.XPath("//*[@id='origin']"))); hover.Build().Perform(); Thread.Sleep(2000); hover.SendKeys("MAQ"); hover.Click(); both are not working..... how to enter text here and how to choose the respective stationAishwarya Mohan

3 Answers

1
votes

from input try the below css :

p-autocomplete#origin input

To input try the below css :

p-autocomplete#destination input

Code :

driver.FindElement(By.CssSelector("p-autocomplete#origin input")).SendKeys("MAQ");
driver.FindElement(By.CssSelector("p-autocomplete#destination input")).SendKeys("some to station");

and if you wanna do Keyboard enter then probably use it with sendkeys():

something like this :

driver.FindElement(By.CssSelector("p-autocomplete#origin input")).SendKeys("MAQ" + Keys.RETURN);
0
votes

See if this works:-

driver.FindElement(By.XPath("//label[text()='From']/..//input")).SendKeys("MAQ");
//Add a wait time for the drop down value to load
Actions builder = new Actions(driver); 
Actions hover = builder.MoveToElement(driver.FindElement(By.XPath(".//ul[@id='pr_id_1_list']/li"))).Click().Perform();
0
votes

You can try this code. For debugging see the Fromstn object in the quick watch and see if it has returned the correct element. for debugging you can also see the element is still in the form by 'inspect element' and do a find with the Xpath given when you are on the breakpoint.

IWebElement Fromstn = driver.FindElement(By.XPath("//*[@id='divMain']/div/app-main-page/div/div/div[1]/div[1]/div[1]/app-jp-input/div/form/div[2]/div[1]/div[1]/span/i"));
Thread.Sleep(2000); //you can also try by increasing the value for testing say 10 seconds
Fromstn.Clear();
Fromstn.SendKeys("MAQ");
Fromstn.Click();