Issue
I tried a lot to locate elements on this page with this href="https://www.booking.com/hotel/eg/royal-tulip-alexandria.html?aid=304142;label=gen173nr-1FCAEoggI46AdIM1gEaEOIAQGYATG4ARfIAQzYAQHoAQH4AQKIAgGoAgO4AqSOmI8GwAIB0gIkYThmZDc0NWMtNTA0YS00ZmI5LWFmZDMtOTkwYWI0MDNhMDU52AIF4AIB;sid=16c7a8afce639ab8d05c8311b384ec50;all_sr_blocks=78883120_334792541_2_1_0;checkin=2022-04-01;checkout=2022-04-14;dist=0;group_adults=2;group_children=0;hapos=1;highlighted_blocks=78883120_334792541_2_1_0;hpos=1;matching_block_id=78883120_334792541_2_1_0;no_rooms=1;req_adults=2;req_children=0;room1=A%2CA;sb_price_type=total;sr_order=popularity;sr_pri_blocks=78883120_334792541_2_1_0__112600;srepoch=1642465068;srpvid=af0c0214b97f013b;type=total;ucfs=1&#hotelTmpl" rel="nofollow noreferrer">link
ALL I want to do is to select "1 queen bed" or "1 double large bed" and then select amount from the drop down list then press, I'll reserve button.
But I totally failed trying all of these:-
- using Action --> moveToElement --> perform()
- using JS Execution --> scrollToView, scrollBy(0,100) for example to make the page scroll down
- using all types of locators (ID, xPaths, cssSelectors, names) but always an error message that Expected condition failed: waiting for visibility of element located by By.xpath- By.id .. etc.
- tried to search for an iFrame but I didn't find but I think there are some but not related to the locators I want
- Thread.sleep() to wait for a time if the element is not loaded on the web page.
I am using Selenium JAVA TestNG
so in the page I write this function:-
Page class I write this function :-
private By btnBed = By.xpath("(//i[@class='bicon bicon-double'])[1]");
public void clickBed(){
// JavascriptExecutor exe = (JavascriptExecutor)driver;
// exe.executeScript("window.scrollBy(0,1000)");
click(btnBed);
}
In my Test I write this:-
hotelPage.clickBed();
Error message:-
Expected condition failed: waiting for visibility of element located by By.xpath
Solution
The problem was that this page was opened in a new tab so the code can't locate any elements on the screen. So I just switch tabs, the code works fine.
Answered By - Bishoy Ezzat
Answer Checked By - David Marino (JavaFixing Volunteer)