0

I need to click on the Select Room button on this web page using Selenium and Xpath. However none of the selectors that I have tried seem to work.

//button[contains(text(), 'Select')]

will not work as it is not unique.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
SBRoy
  • 13
  • 3
  • Which Select Room do you want to click? If you say there are more? Give us more details. – KunLun Jul 11 '20 at 08:59
  • @KunLun i was editing the question. I would like to click on the first. This is a hotel booking website and upon entering location you get a list of options. we need to select the first option, which gives brings up the View N Rooms after that we need to click on Select Room on the first room shown. kindly help. – SBRoy Jul 11 '20 at 09:00
  • Have you tried `(//button[contains(text(), 'Select')])[1]`? – KunLun Jul 11 '20 at 09:01
  • @KunLun yes, it does not seem to work when running the script. – SBRoy Jul 11 '20 at 09:03
  • Can you show us the code you try to run? – KunLun Jul 11 '20 at 09:14
  • I have just tested you xpath with chromedriver and everything seems to work. What is your issue exactly? – Alexey R. Jul 11 '20 at 12:15
  • xpath locator you are using is pointing to same button instance. Now I don't know which one is the active try all 3 locators. (//button[contains(text(), 'Select')])[1] (//button[contains(text(), 'Select')])[2] (//button[contains(text(), 'Select')])[3]. Use JavascriptExecutor to click on the button. – Shrini Jul 11 '20 at 16:03

2 Answers2

0

Have you tried using the Xpath of the "Select Room" button?

#try this
#insert the xpath of the "Select Room" button element

button = driver.find_element_by_xpath().click()
frianH
  • 5,901
  • 6
  • 13
  • 36
0

To click on SELECT ROOM button for the first Room Type you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    driver.get("https://www.goibibo.com/hotels/sterling-ooty-elk-hill-hotel-in-Ooty-2300020804682931682/?hquery=%7B%22ci%22:%2220200715%22,%22co%22:%2220200716%22,%22r%22:%221-2-0%22,%22ibp%22:%22v3%22%7D&hmd=dacdbc1b43518ece5284c57e889be4a87cc77193f605a25ed4ddbe075bfe72b50c00212e846ffe0c4d7c14c0c2e99e1f40aca6cc0f778c8744e79e26f88866c20ebbd2cee32e2b6cf2c8b5af0de595bae20e654d05992eb728f7ddf37568b56d5c81bb8ac295450b84325b36e5120e8a6c03a734f1db8b74774fdff16746415297313331343db0030c5fc7459538a2014739addf9286645500cac56ad4f8c63de9aa897df81e7b5c4a65a87cb547f68c67f73b28ab81b51b5c7eb9f44b74bbeb13e8f020604d6a6122c86b4ac1988d80e57a2632e518ee111133feebf7fc7b19dc7ca235d802fc3723de2910739aa363191808950f137910bc50af1b78aefe5f7cb119732470e54ceae95944fe242a583e96e7e68ed5618ddbb9f3df324bddee3639f3fe60a0b43aae1903c5c70296b3f530f37909cfed64d6bac2db1529e3759c957d466f83bd58380f3d18ebd39a58195250cdff3970687780870948e8&cc=IN");
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[class^='RoomFlavorstyles__ButtonWrapper']"))).click();
    
  • xpath:

    driver.get("https://www.goibibo.com/hotels/sterling-ooty-elk-hill-hotel-in-Ooty-2300020804682931682/?hquery=%7B%22ci%22:%2220200715%22,%22co%22:%2220200716%22,%22r%22:%221-2-0%22,%22ibp%22:%22v3%22%7D&hmd=dacdbc1b43518ece5284c57e889be4a87cc77193f605a25ed4ddbe075bfe72b50c00212e846ffe0c4d7c14c0c2e99e1f40aca6cc0f778c8744e79e26f88866c20ebbd2cee32e2b6cf2c8b5af0de595bae20e654d05992eb728f7ddf37568b56d5c81bb8ac295450b84325b36e5120e8a6c03a734f1db8b74774fdff16746415297313331343db0030c5fc7459538a2014739addf9286645500cac56ad4f8c63de9aa897df81e7b5c4a65a87cb547f68c67f73b28ab81b51b5c7eb9f44b74bbeb13e8f020604d6a6122c86b4ac1988d80e57a2632e518ee111133feebf7fc7b19dc7ca235d802fc3723de2910739aa363191808950f137910bc50af1b78aefe5f7cb119732470e54ceae95944fe242a583e96e7e68ed5618ddbb9f3df324bddee3639f3fe60a0b43aae1903c5c70296b3f530f37909cfed64d6bac2db1529e3759c957d466f83bd58380f3d18ebd39a58195250cdff3970687780870948e8&cc=IN");
    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(., 'Select')]"))).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217