Using Selenium to locate an element by CSS and submitting a form

I am new to using selenium and I have a few questions about my first script.

driver.findElement({ css: '.input[name=login]' }).sendKeys('login');
//driver.sleep(0);
driver.findElement({ css: '.input.passwd' }).sendKeys('passwd');
driver.sleep(5000);
driver.findElement({ css: '.button[type=submit]' }).click();                        
driver.sleep(10000);
driver.getTitle().then(function(title) {
    console.log(title);
    assert.ok(title.indexOf('Title') > -1, 'Wrong title');
}

Upon execution, I find myself still on the login page with only one error message stating "AssertionError: Wrong title". Even though Selenium typically throws an error if an element cannot be located (such as "NoSuchElementError: no such element: Unable to locate element:"), all elements seem to have been found and all actions like "sendKeys" and "click" were successful. However, this does not appear to be the case.
How can I verify this during the execution of the script?
Is there a way for me to view the query that Selenium generated and sent to the server?

UPD:

<input name="login" value="" type="text" class="input" tabindex="5">
<input name="" value="" type="password" class="input passwd" tabindex="6">
<input hidefocus="true" type="submit" class="button"></input>

Answer №1

You have applied the class attribute to an HTML tag. For instance, class=input and name=login both belong to the WebElement of the <input> tag. You can try:

driver.findElement({ css: 'input[name="login"]' }).sendKeys('login');
driver.findElement({ css: '.passwd' }).sendKeys('passwd');
driver.findElement({ css: '.button' }).click();

Alternatively,

driver.findElement({ name: 'login' }).sendKeys('login');
driver.findElement({ className: 'passwd' }).sendKeys('passwd');
driver.findElement({ className: 'button' }).click();

Or you can use the By class as well:

driver.findElement(By.name('login')).sendKeys('login');
driver.findElement(By.className('passwd')).sendKeys('passwd');
driver.findElement(By.className('button')).click();

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

Creating a responsive div class that is centered

Struggling to center my <div class="loginfeld"> while keeping it responsive. <html> <body> <div class ="loginfeld"> <div class="container"> <div class="col-lg-4"></div> ...

Encountering an error in Jest with TypeScript (Backend - Node/Express) that reads "Cannot use import statement outside a module

Currently, I am in the process of developing Jest tests for a Node/Express TypeScript backend. Recently, I came across the concept of global test setup which I am integrating to streamline the usage of variables and function calls that are repeated in all ...

Navigating Angular's Resolve Scope Challenges

As a junior developer, I've been diving into Angular.js and exploring the resolve feature of the route provider to preload my Project data from a service before the page loads. Previously, I was fetching the data directly inside the controller. Howeve ...

Is there a way to send an array of objects to my Express / SQL Server in react?

I am currently facing a challenge with passing an array of objects to my back end (SQL Server). Below is the specific array of objects: console.info(results) Here is the array of objects named results: [0] [ [0] { [0] answer: 'bmbm,nn', [ ...

What is the interaction between CSS and URL fragments (the #stuff)?

Can URL fragments affect CSS behavior? For instance, let's consider a sample page at: http://example.boom/is_this_a_bug.html. You can view the code for this page on https://gist.github.com/3777018 Upon loading the page with the given URL, the element ...

What is the best way to configure the time to T00:00:00.000Z in JS?

In my usage of ui-calendar, I am attempting to pass events without a specified time. Currently, I am retrieving the date and time in the following manner. var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); ...

What is the process for creating a folder using Firebase Cloud Functions with Storage?

How do I create a folder named "posts"? Storage bucket path --> gs://app.appspot.com/posts Code to generate thumbnail from storage object exports.generateThumbnail = functions.storage.object() .onChange(event => { const object = event.data ...

How to animate a left border shifting to the center using JavaScript

As I'm modifying my current div, I need to add a vertical line in the center of it. I've come across various solutions where a left border is added and then shifted using the left property by 50% (which effectively places it in the middle). Here ...

TypeScript compilation error - No overload is compatible with this call

Currently, I am working on a project using TypeScript alongside NodeJS and Express. this.app.listen(port, (err: any) => { if (err) { console.log("err", err) } else { console.log(`Server is listing on port ${port}`); } }); The co ...

Using Ajax to implement the Modal IF functionality

Currently in the process of registering a domain, utilizing two modals in the process. Through Ajax, I have set it up so that if the response is 1, an alert stating that the domain is available is displayed. If the response is 0, an alert stating that the ...

Steps to resolve the problem with dynamically generated text fields in Angular

For my current project, I'm implementing Angular and working with a JSON object that looks like this: items={"departure":"New York","arrival":"California","stations":[{"station":"toto"},{"station":"titi"},{"station":"tata"}]} I attempted to display ...

Unable to locate the iframe in the test scenario

I encountered this particular test case: Select Frame id=coach_frame63454108.cf1 Wait Until Element Is Visible ${ap.gui.header.appname} Page Should Contain Element ${ap.gui.header.appname} Page Should Contain Element ${ap.gui.hea ...

When using the <object> tag, it may not always render at 100% height as intended

Application Inquiry I am seeking assistance with a web page that features a title, and a sticky menu bar at the top, allowing the rest of the space for displaying content. When a menu item is clicked, the objective is to load a page in the content at full ...

Expanding and Shrinking Text Areas with Jquery

I am looking to create a textarea that comes preloaded with content. The height of the textarea should adjust to auto when there is content present, but switch to a height of 4.2rem when it is empty. Additionally, I want the textarea to dynamically increas ...

Mastering the Art of Customizing Styling in Ant Design

I'm currently working with a table from Ant Design, but I'm facing an issue where the padding or margin applied by the Ant Design CSS is preventing the table from expanding on the left side. The table has an inline CSS of table layout: auto which ...

Experiencing challenges with ng-repeat and the concept of 'distinct'

I'm facing a perplexing issue. When utilizing ng-repeat to iterate through my data and create checkboxes, I encounter unexpected behavior. The result is multiple duplicate items being displayed instead of unique ones. Here's an example: <lab ...

Count insensitivities - Javascript

I'm currently using a counter to find occurrences of a substring within a string, but it's case sensitive. Here's my current code: count = (string.match(new RegExp(substring, 'gm')) || []).length; For instance, if the substring a ...

Transforming button hues and passing a property to a subcomponent when clicked using vue.js

Just starting out with vue.js, I am attempting to create a component that functions in the following way: I have four buttons and when I click on one button, I want to change the colors of all four buttons and send a prop to a child component indicating w ...

What is the best way to conduct tests on React components' methods and ensure they are integrated into my Istanbul coverage report

Is there a way to test the methods of react components and include them in my Istanbul test coverage? Edit: I'm using enzyme. Just wanted to mention that. Take, for instance, this component: class SearchFormContainer extends Component { static h ...

Troubleshooting issue: AngularJS NVD3 line chart directive does not refresh after data update (not updating in real time)

I am currently facing an issue with the nvd3-line-chart directive in my AngularJS application. The chart does not redraw when I change the underlying model... As a newcomer to AngularJS, there may be something obvious that experienced programmers will not ...