Clearing up confusion around identifying checkbox elements using XPath in Selenium WebDriver with Java, specifically within a

HTML code

<div class="modal-footer slds-modal__footer" data-aura-rendered-by="2805:0">
<div class="rssDialogText grantAccessCheckbox packagingSetupUIRssDialogFooter" data-aura-rendered-by="2595:0" data-aura-class="packagingSetupUIRssDialogFooter">
<input type="checkbox" id="2596:0" data-aura-rendered-by="2600:0" class="uiInput uiInputCheckbox uiInput--default uiInput--checkbox" data-aura-class="uiInput uiInputCheckbox uiInput--default uiInput--checkbox" data-interactive-lib-uid="157">

Action:

Clicking the Checkbox

my customized xpath

//input[@data-aura-class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']

or

//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']

Unfortunately, both xpaths are not functioning properly and resulting in an error stating "no such element".

no such element: Unable to locate element: {"method":"xpath","selector":"//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']"}

Code for clicking the checkbox:

driver.findElement(By.xpath("//input[@class='uiInput uiInputCheckbox uiInput--default uiInput--checkbox']")).click();
driver.findElement(By.xpath("//input[@data-aura-class='uiInp‌​ut uiInputCheckbox uiInput--default uiInput--checkbox']")).click();

Note: The ID of the checkbox is dynamic.

Please provide a solution or correct my xpath

https://i.stack.imgur.com/LiFKO.png

Answer №1

It appears that there might be a timing issue here: if the input field is generated dynamically, it may not initially be present in the DOM. You can try using the following code to wait until the checkbox is present in the DOM and clickable:

WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@data-aura-class='packagingSetupUIRssDialogFooter']/in‌put[@type='checkbox']"))).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

Is Openshift compatible with selenium testing tools?

Can Openshift support GUI applications like Selenium? I am looking to deploy my Python application in the cloud... If not, is there a way to work around this issue? The application needs to log into a website and perform tasks for a few seconds.. ...

Errors occurred when trying to use Jquery to handle a JSON response

enter code here function customPaging(action, action1, page) { alert("in customPaging"); $.getJSON("./paging.do?action="+escape(action)+"&p="+escape(action1)+"&str="+escape(page), function(data){ alert("Length: "+data.length); var options = ...

Navigating the Yahoo login process using Selenium with Python (testing various techniques)

Currently, I am experimenting with logging into my Yahoo account using Selenium. This is part of my learning process as I am trying to familiarize myself with Selenium by creating programs for various websites. Despite my efforts, I have encountered diffi ...

Using Selenium to interact with a complex element on a web page

I need to identify the label tag that contains an input tag with a value of 14860 and then trigger a click event on it. What method should I use in Selenium to achieve this? The traditional options like By.id or By.tagName seem ineffective in this scenar ...

Decoding a JSON array containing multiple JSON objects into an ArrayList of org.json.JSONObject instances using Gson

I have a JSON string that looks like this: { "r": [ { "pic": "1.jpg", "name": "Name1" }, { "pic": "2.jpg", "name": "Name2" }, { "pic": "3.jpg", "name": "Name3" } ] } My goal is to convert it ...

Using the following-sibling selector in Java, you can easily click on all <li> elements within a <ul> tag

I am trying to navigate through the list of li elements starting from the "Mentorship" tag link <ul _ngcontent-cwp-c18="" class="navigation clearfix"> <li _ngcontent-cwp-c18="" routerlinkactive="current" ...

Error encountered while utilizing By.Xpath: NoSuchElementException

Update : After some trial and error, I managed to make it work by placing the element inside an iframe: WebDriverWait wait = new WebDriverWait(_driver, 60); wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By .xpath("//*[@cla ...

The issue with Protractor's sendkeys function is that it requires an X display for converting keycodes

I've encountered an issue while attempting to execute Protractor e2e tests in a Vagrant VM using headless Chrome. Despite successfully configuring Xvfb, I face an error when trying to fill out a form: unknown error: an X display is required for keycod ...

Tips on waiting for the user to click before proceeding with the rest of the automation process

I am working on automating a form filling process using code. However, I would like the automation to pause and wait for the user to manually click after reading a notice before proceeding. postalcode = driver.find_element(By.NAME, 'postalCode') ...

Discovering webElements on Facebook using Selenium with Java

I'm currently working on a test script to post on my Facebook wall, but I have encountered an issue - I am unable to locate the element (getting an NoSuchElementException) even though I know it exists. I tried using FirePath to find a cssSelector, but ...

Choosing a radio button using Selenium

Having trouble selecting the 'Government & Military' radio button on this page using Selenium. Tried different methods with the below code, but nothing seems to be working: from selenium import webdriver browser = webdriver.Chrome('/Us ...

What is the process of encoding a String in AngularJS?

Utilizing Angularjs for sending a GET HTTP request to the server, which is then responded to by the Spring MVC framework. Below is a snippet of code depicting how the URL is built in Angular: var name = "myname"; var query= "wo?d"; var url = "/search/"+qu ...

Selenium failing to refresh the current window

It seems like Selenium is retrieving data from an old page instead of the new one. I am attempting to automate a search process where I have to select an option from a dropdown menu and enter a value into a text box. from selenium import webdriver from se ...

"Troubleshoot: Resolving Issues with Opening URLs in Selenium from a

I am encountering an issue while trying to open URLs from a TXT file using the Selenium WebDriver. The code I am using is written in Python 3.4.3. Could you help me identify the problem in this code? from selenium import webdriver with ope ...

Navigating my path with precision using XPath

Currently, I am utilizing webdriver.find_element_by_link_text('searchterm') in Selenium to retrieve a webElement. Once obtained, I extract the value of href by using webElement.get_attribute('href'). Subsequently, I am able to pinpoint ...

Contrasting reactions when running commands in Selenium through scripts versus manually

My goal is to use Selenium to show a table with the maximum number of rows possible. This can be achieved by utilizing a button that adjusts the row count in the table. I've constructed a script for this purpose: url = 'http://www.side.developpe ...

Getting a SyntaxError when attempting to use WebDriverWait to automate clicking a button in Selenium with

Issue at hand: My code is running smoothly until I introduce a segment that involves clicking an arrow on the product square/profile. Main concern: While the code as a whole functions properly, the dataset it retrieves is distorted. Upon further investiga ...

Android response JSON scrambled

The server's response looks something like this: { "data": { "table": { "0": { "pay_date": "2017-04-28", "status": "Paid", "bill_date": "2017-04-27", }, "1": { "pay_date": "2 ...

Double Serialization with Java's Jackson Library

In my code, I have a class that includes a String field and a Map field. My goal is to serialize this class into JSON using Jackson. public class Mapping private String mAttribute; @JsonIgnore private Map<String, String> mMap; @J ...

Tips for creating JSON parser Entity Objects for Currency Converter API with this desired Output

I have a project in which I need to retrieve currency values from an external API converter at to perform conversions between different currencies. For example, if I use the endpoint , it will return the following data: { "rates": { "GBP": 0.761 ...