I am currently in the process of conducting an automated test focused on the creation of a new Facebook account

I am currently facing a challenge while attempting an automated test on Facebook. The issue lies in clicking the "Create Account" button using FindElement by id, which is not functioning as expected.

public void createAccount(String firstName, String lastName, String emailAddress, String userPassword) {

    driver.findElement(By.id("u_0_2_OE")).click();
    
    WebElement firstNameElement = driver.findElement(By.name("firstname"));
    
    firstNameElement.sendKeys("Test");
    
    
    WebElement lastNameElement = driver.findElement(By.name("lastname"));
    
    lastNameElement.sendKeys("Alfasoft");
    
    
    WebElement emailElement = driver.findElement(By.name("reg_email__"));
    
    emailElement.sendKeys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="791f181b1016570d1c0a0d1c3918151f180a161f0d57090d">[email protected]</a>");
    
    
    WebElement passwordElement = driver.findElement(By.name("reg_passwd__"));
    
    passwordElement.sendKeys("AlfasoftTeste_");
    
    
    driver.findElement(By.name("birthday_day")).click();
    
    WebElement dayElement = driver.findElement(By.id("day"));
    
    dayElement.sendKeys("6");
    
    
    driver.findElement(By.name("birthday_month")).click();
    
    WebElement monthElement = driver.findElement(By.id("month"));
    
    monthElement.sendKeys("Aug");
    
    
    driver.findElement(By.name("birthday_year")).click();
    
    WebElement yearElement = driver.findElement(By.id("year"));
    
    yearElement.sendKeys("1999");
    
    
    driver.findElement(By.id("u_h_3_BO")).click();
    
    
    driver.findElement(By.name("websubmit")).click();
    
}

(I am invoking this code in another Class using:

public static void main(String[] args)
throws Exception and then
tarefa2Project.createAccount("firstName", "lastName", "emailAddress", "userPassword");
...

Answer №1

One strategy would be to utilize the xpath method by leveraging both the element's attributes and text content to ensure uniqueness:

driver.findElement(By.xpath("//a[@role='button'][text()='Create New Account']")).click();

Answer №2

One way to avoid relying on the text of an element and refrain from using xpath is by utilizing this unique css selector:
li>a[role='button']

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

What is the best way to filter out duplicate objects in JavaScript?

I have the following code snippet: let self = this; self.rows = []; self.data.payload.forEach(function (item, index) { if (!(self.rows.includes(item))) { self.rows.push(item); } }); The issue is that includes always returns false. Each ite ...

Inadequate termination of the while loop

I'm trying to generate a line of text in JavaScript running in Node, ensuring that it does not exceed a certain number of syllables. To achieve this, I have created a function utilizing the "syllable" library as follows: function generateLine(maxSyll ...

Executing several GET requests in JavaScript

Is there a more efficient way to make multiple get requests to 4 different PHP files within my project and wait for all of them to return successfully before appending the results to the table? I have tried nesting the requests, but I'm looking for a ...

Show a dynamic highchart graph displaying linear data retrieved from the database

I am attempting to present data retrieved from a database in a linear highchart format. Here is the JSON response from my database: [{"protocol":"tcp","date":"01/02/20","time":"00:10:20","total":281}, {"protocol":"udp","date":"01/02/20","time":"00:10:30", ...

Is there a way to have a button function as a submit button for a form even when it is located in a separate component within a react application?

I am in the process of creating a user-friendly "My Account" page using react, where users can easily update their account information. I have divided my components into two sections: the navbar and the form itself. However, I am facing an issue with the s ...

Ways to retrieve property value from a component in Vue.js 2.0

I am currently working with a specific component that allows for date selection: <template> <div class="animated fadeIn"> <div class="col-sm-6 col-lg-6"> <datepicker class="form-control" :value="config.state.fromDate" ...

"Jquery's .append function may sometimes display as undefined when

$("#clckjson").click(function() { $(document).ready(function() { $.getJSON("fuelj.json", function(data) { $(data).each(function(i, item) { console.log(item.stationID); var $table = $('<table>'); $table.a ...

Creating a Vue.js component during the rendering process of a Laravel Blade partial view

In my Vue.js project, I have a component that is used in a partial view called question.blade.php: {{--HTML code--}} <my-component type='question'> <div class="question">[Very long text content...]</div> </my-component& ...

Using React.js to create a search filter for users

When using useEffect with fetch(api) to set [search], I encounter an issue where "loading..." appears each time I enter something in the input box. To continue typing, I have to click on the box after every word or number. I am seeking advice on how to pr ...

Is there a way to create a JavaScript script that automatically updates a webpage for all users simultaneously?

I have developed a web application that enables users to modify content using JavaScript. Currently, these changes are only visible on the local browser and do not involve AJAX. However, I am wondering how I can ensure that these DOM alterations are refle ...

Tips for preserving the contents of a list with HTML and Javascript

My latest project involves creating a website with a To-Do list feature. Users should be able to add and delete items from the list, which I achieved using JavaScript. Now, my next goal is to ensure that the current items on the list are saved when the pag ...

Enhance the "content switcher" code

I have been working on improving my "contenthandler" function. It currently changes different articles when I click different buttons, which I am satisfied with. However, I believe there may be a better approach to this and would appreciate any advice on h ...

A guide to extracting attribute values from HTML using Angular 4

I am currently working on an Angular 4 project where I needed to implement drag and drop functionality. To achieve this, I utilized the ng2-dragula plugin. Now, I have a new requirement which involves extracting the data-id attribute from each row after it ...

What is the reason why calling setState does not update the local state?

Hello everyone, I came across an intriguing React task and I'm struggling a bit with finding the solution. Task: Can you figure out why this code isn't working and fix it? Code: class BugFixer extends React.Component { constructor(props) { ...

Fetching Results from Promise

Repeatedly, this question has been asked in various forms but I still do not understand: I have a resolved promise with a value. When I console.log this object, everything appears to be functioning correctly. I can see exactly what I want to see. My setu ...

Can WebDriver (HtmlUnit, Ruby bindings) be configured to bypass JavaScript exceptions?

When attempting to load the page, HtmlUnit throws an exception and crashes my test. caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true) driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps) drive ...

best way to eliminate empty p tags and non-breaking spaces from html code in react-native

How can I clean up dynamic HTML content by removing empty <p> tags and &nbsp? The whitespace they create is unwanted and I want to get rid of it. Here's the HTML content retrieved from an API response. I'm using the react-native-render ...

Tips for duplicating specific div elements

Is there a way to create copies of selected divs within the same panel using a Javascript report designer? I attempted to achieve this by using the following code snippet: function DesignerClone() { $(".ui-selected").each(function () { va ...

Failure to execute Ajax request when searching for a query

My personal GitHub profile viewer React application allows you to search for a profile by username. By default, my own GitHub username is provided on the landing page. However, when trying to search for another user, my ajax call is not functioning properl ...

The issue with executing event.keyCode == 13 in Firefox remains unresolved

I've implemented a function that sends comments only when the "enter" key is pressed, but not when it's combined with the "shift" key: $(msg).keypress(function (e) { if (event.keyCode == 13 && event.shiftKey) { event.stopProp ...