What could be causing the failure of isElementPresent function?

Here is a simple code snippet that waits for a dropdown list to be displayed on the page:

var By = this.webdriver.By;
var driver = this.driver;
var bySelector = By.xpath('//*[@id="searchForm"]//*[@class="autocomplete-suggestions autocomplete-suggestion-withgroup"]');
return driver.wait(() => {
    driver.isElementPresent(bySelector);
    }, 6000)
    .then((bool) => {
        assert.isTrue(bool);
    });

Unfortunately, when running this code, I receive an error message:

Error: Wait timed out after 6011ms

The element in question has the following properties: https://i.sstatic.net/gK1ui.png

When clicking on the search field, the style property display: of this element changes from none to block. I am unable to see anything in the parent elements, which suggests that the element is invisible. I am unsure of what mistake I may have made.

I need to click on an item in this dropdown list and currently can only do so after using this.driver.sleep(some ms). However, I know that this is not good practice and would like to understand where I went wrong when using the wait method and how to correct it. Thank you.

Answer №1

It appears that the xpath you have implemented is incorrect. Please consider using the following xpath instead:

var selector = By.xpath('//*[@id="searchForm"]/descendant::*[@class="autocomplete-suggestions autocomplete-suggestion-withgroup"]');

Answer №2

I received assistance from a coworker in finding a solution to the issue at hand. Here is the code snippet shared with me:

return driver.wait(until.elementLocated(bySelector), 500, 'not found').then((element) => {
    return driver.wait(until.elementIsVisible(element), 5000, 'not found');
});

It's interesting how sometimes isElementPresent is enough, but in this particular case, two expectations need to be defined. I would greatly appreciate it if someone could clarify this for me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with rvest's html_table() function causing it to return -Inf when the maximum value

Recently, I've been working on scraping tables from websites and I'm currently trying to extract a table from . After some research, I found that using the rvest library along with the html_table() function worked best for me. In fact, I successf ...

Creating a map in Typescript initialized with a JSON object

In my Typescript class, there is a map that I'm trying to initialize: public map:Map<string,string>; constructor() { let jsonString = { "peureo" : "dsdlsdksd" }; this.map = jsonString; } The issue I'm encounte ...

Is there an alternative to the outdated pause method in Selenium Webdriver Actions?

Upon reviewing the Selenium Webdriver documentation (http://selenium.googlecode.com/git/docs/api/java/index.html), I came across the deprecated pause() method. Although it is considered bad practice, my scenario requires a simulated pause. How can I achie ...

Concealing the Command Prompt window of PhantomJS in Python using Selenium

Does anyone know how to hide the CMD window that pops up when launching PhantomJS using Python? from selenium import webdriver browser = webdriver.PhantomJS() I found a potential solution for C# on Stack Overflow, but couldn't find anything similar ...

Switching measurement unit to jQuery when retrieving image weight

After coming across a solution on this question, I am looking to determine the weight of an image from a file input. The solution I found displays the result in MiB (Mebibyte) unit. Is there a way to show the image weight using the same code, but in a diff ...

What is the best way to showcase one object per day when I have an array of 30 objects in Ionic 4?

I'm looking to showcase a different quote in my app every day for 30 days using an array of 30 quotes. How can I achieve this daily quote rotation in Ionic 4? ...

How to upload multiple files using AngularJS and Laravel without using a form tag

I am seeking a solution to upload multiple files without using the form tag, utilizing AngularJS with Laravel 5.2. The code snippet below is functional for uploading a single file but fails when attempting to upload multiple files. Here is the HTML Code: ...

There is no need for updates as git is already current for some mysterious reason

As a newcomer to git, I've been trying to wrap my head around it but still struggling. Can someone help clarify this for me? My question pertains to the 'master' branch in git which contains the following code: const list = [ 'h&ap ...

What is the method for inputting text into a textbox during automation testing?

I am currently testing out c# with selenium on the website . One of the first steps is to log in to the site. To do this, I located a button named "Вход" in the top right corner using xpath and clicked on it. After the page refreshed and changed, the ...

Tips for designing a multi-level dropdown navbar

I am currently facing an issue with designing a navbar. I am aiming for Multi-Level Dropdowns, but whenever I click on More Services, it automatically closes the main dropdown menu. I have experimented with various approaches, but none of them seem to be ...

Tips for hiding the overflow scrollbar on Microsoft Chrome when there is no content to scroll

Looking for a solution to hide scroll bars in Microsoft Chrome, but only when there is no content to scroll? The current div and styles always show the horizontal and vertical scroll bars, even when the height exceeds the content. <div style="backgroun ...

"Can anyone provide guidance on how to initiate a css 3d animation by clicking a button

Currently, I am developing a folding hide/show animation that can be triggered using Javascript. If you would like to take a look at the code and see a working example, please visit this link: You can also view just the gist here: https://gist.github.com ...

generate a cookie within a pop-up window

Can someone help me figure out why my Modal Window with a cookie to display only once isn't working? I followed this tutorial at . Here is the link to my website: Here is my code: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" a ...

Setting the cache to false during an httpget request in an mvc4 controller action: tips and tricks

My httpget request to a controller action looks like this: $.get('/Course/ExplanationCorrect/', postData, function (data) { $('#SurveyDiv').html(data); }); While it works on all other browsers, I'm facing an issue with IE10 o ...

Simple steps for retrieving URL parameters with AngularJS

HTML source code <div ng-app=""> <div ng-controller="test"> <div ng-address-bar browser="html5"></div> <br><br> $location.url() = {{$location.url()}}<br> $location.search() = {{$locati ...

How can a JSON string be assigned to a variable for use in a Google pie chart?

I am currently experiencing an issue with my web server. I am sending a JSON object as an argument via render_template to my website, where I intend to use this data to display a Google pie chart. The problem arises when I try to assign the Google pie cha ...

Create a Discord.js bot that automatically deletes any URLs that are posted in the server

Seeking advice on how to have my bot delete any URLs posted by members. I am unsure of how to accurately detect when a URL has been shared, especially since they can begin with https, www, or some other format entirely. Any insights would be greatly apprec ...

retrieve the information from a specific field within the store and store it in an array

Perhaps this is a question that pertains to using pure JavaScript, but for some reason I can't seem to figure it out. I am currently working on extjs4.2 using Sencha Architect and have received a JSON response from the server in the following format: ...

Issue with transmitting Razor form data to API controller using fetch or AJAX

I have created a basic razor web project and defined it as follows: in program.cs I added builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN"); In the controller, this is what I did: [Route("/api/[controller]")] [ApiCon ...

When I toggle the div to close on mobile, I want it to show on desktop

My attempt at creating a toggle button to hide and show content was not successful. I struggle with coding in Javascript/Jquery. In the desktop view, the description displays perfectly (see image here), but in mobile view, there is a button to toggle hidi ...