0
<input type="submit" name="ccBtnBook" value="Book" id="ccBtnBook" 
class="bookbtn2 flR" style="background-color:Transparent;border- 
style:None;">

<input type="submit" name="ccRepItinerary$ctl00$ccLbtnSelect" value="Book" 
id="ccRepItinerary_ctl00_ccLbtnSelect" class="bookbtn2" style="background- 
color:Transparent;border-style:None;">

<input type="button" value=" Book " class="bookbtn2" onclick="iSB('1')">

<input type="button" value=" Book " class="bookbtn2" 
onclick="iSB('4','MCT','DXB','DXB','MCT','True')">

<input type="button" value=" Book " class="bookbtn2" 
onclick="iSB('1','MCT','DXB','','','False')">

<input type="button" value=" Book " class="bookbtn2" onclick="iSB('4')">

I have tried using the class name and xpath, but failed for both. I even tried to use a JavaScript click.

For case two finding the element by its ID works.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Adheen
  • 1
  • 1
  • 2
    You mean the element could be any one of those options? you should also post what you tried and what was the problem with it? – Guy Nov 15 '18 at 06:40
  • I have edited the context – Adheen Nov 15 '18 at 06:45
  • You didn't add any new information. *I have tried using* doesn't mean anything. Post the code and tell what happened when you tried it. If there is an error message post it as well. – Guy Nov 15 '18 at 06:47
  • driver.findElement(By.className("bookbtn2")).click(); – Adheen Nov 15 '18 at 06:50
  • WebDriverWait wait = new WebDriverWait(driver,50); wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input.bookbtn2"))); – Adheen Nov 15 '18 at 06:50
  • Error is, Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not interactable – Adheen Nov 15 '18 at 06:54

2 Answers2

0

Use the class, that seems to be common

//*[contains(@class, 'bookbtn2')]
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
0

As per the HTML you have shared to locate the element in four different scenarios you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("input.bookbtn2[value='Book'][type='button'][onclick^='iSB']"));
    
  • xpath:

    driver.findElement(By.xpath("//input[@class='bookbtn2' and @value='Book'][@type='button' and starts-with(@onclick,'iSB')]"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352