-2

I am trying to automate a travel application. I logged in with user name and I tried to click book travel. But is showing the below error while I was trying to click travel.

FAILED: BookTravel org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='ctl00_mnuTraveln0']/table/tbody/tr/td/a"}

screen shot

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
  • 1
    in which language you code ? – Ashish Kamble Oct 11 '18 at 12:12
  • 1
    Welcome to Stack Overflow! Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Oct 11 '18 at 13:57
  • Have you tried `By.linkText("Book Travel")` or some variation? What else have you tried? Update your question with what you've tried and what the results were. – JeffC Oct 11 '18 at 13:57
  • I have tried with link text , but not working. I tried with xpath, href, linktext.. I think i need to handle this with frames. I am not sure how to search for the frame id or how to handle frames.. The output is i am getting " No such element exception". This could be handle by frames. – siva kumar Oct 12 '18 at 06:53

1 Answers1

1

I hope you know C#, this code might help you,

Driver.FindElement(By.XPath("*//a[text()='Book Travel']"));

in java,

driver.findElement(By.xpath("*//a[text()='Book Travel']"));

check this might helpful,

driver.findElement(By.xpath("*//a[@href='TravelRequest.aspx?PID=1']"));
driver.findElement(By.xpath("*//a[contains(@class,'MenuItemStyle')]"));
driver.findElement(By.xpath("*//a[contains(@href,'TravelRequest')]"));

above will not work if there is frames so, you have to calculate frames, how many frames are there is shown using,

int size = driver.findElements(By.tagName("iframe")).size();
driver.switchTo().frame(size);

also using webelement we can switch too,

driver.switchTo().frame(WebElement);

switch between parent or default frames,

driver.switchTo().parentFrame();
driver.switchTo().defaultContent();
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
  • Code is based on Java language.. Not working, i have tried your method @ashish. Same error coming. Thanks! – siva kumar Oct 11 '18 at 12:31
  • can you paste html sample ? – Infern0 Oct 11 '18 at 12:33
  • Same error is coming ... Is it possible with href in selenium. If so, please suggest me – siva kumar Oct 11 '18 at 12:36
  • if you manually apply the xpath of @Ashish, you will see that is working and highlight the element. HTML sample of the html not the element will help, because it can be in iframe. – Infern0 Oct 11 '18 at 12:39
  • @Infern0 ashish xpath is ok. But it is not working. I think , it is in frames.. Can you please suggest me to done this with frame code – siva kumar Oct 11 '18 at 12:42
  • @Ashish Kamble. Thanks for the code. Unfortunately it is not working. Can u help if a code to handle frame – siva kumar Oct 11 '18 at 12:52
  • You may need to inspect for the frame title or id or name. simply meaning is there is tag with the name – Ashish Kamble Oct 11 '18 at 12:56
  • ok before going to find element you have to switch to specif frame first By using frame name or id ok driver.switchTo().frame(driver.findElement(By.name("Book"))); This switches to Book Frame then call FindElement() will surely help you Look this – Ashish Kamble Oct 11 '18 at 13:00
  • Where to get this frame Id? Frame Id is same Id to all modules, ? I am seeing this class name as same in all the modules-- "ctl00_mnuTravel_1 MenuItemStyle ctl00_mnuTravel_3". shall i take this as frame Id,,, – siva kumar Oct 11 '18 at 13:26
  • I found something, called frame, but not in my exact module, some where in the bottom.... . Is this the frame name? – siva kumar Oct 11 '18 at 13:31