Having difficulty finding the element in Selenium WebDriver while using C#

Can anyone help me locate the element in the following HTML tag?

I keep getting an exception: no such element: Unable to locate element:

{"method":"xpath","selector":"//*[@id='divMain']/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/html/body/app-root/app-home/div[3]/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/button"}

IWebElement berthOK = driver.FindElement(By.XPath("//*[@id='divMain']/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/html/body/app-root/app-home/div[3]/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]/button"));
if (berthOK.Displayed)  //*[@id='divMain']/div/app-train-list/div[2]/app-modify-search/p-confirmdialog/div/div/div[3]
berthOK.Click();

Answer №1

Perhaps you are looking to press the OK button.

IWebElement clickOK = driver.FindElement(By.XPath("//span[text()='OK']/.."));
if(clickOK.Displayed)
clickOK.Click();

For added reliability, consider using WebDriverWait :

new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[text()='OK']/.."))).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

Tips for embedding a PHP function within JavaScript code

I am working on enhancing an online application with a translation feature. The application comprises of a frontend coded in HTML and JS, and a backend developed using PHP that is linked to a database. Communication between the frontend and backend occurs ...

Retrieving the value of a formControl within a formArray is made possible through a reactive form in

How can I retrieve the value of ItemName in my HTML code? When I attempt to use {{invoiceForm.controls[i].items.controls.itemName.value | json}}, it returns as undefined. <form [formGroup]="invoiceForm"> <div formArrayName="items" *ngFor="let ...

"Incorporate a personalized dropdown menu (using the datatables plugin) in the designated design structure

Is it possible to add a dropdown list next to the search field in the datatables plugin without positioning it outside where the plugin is initialized? I want to have a custom dropdown list with fixed values, similar to this: https://i.sstatic.net/Fm4zs.pn ...

Tips for showcasing checkbox options on an HTML page (utilizing ejs) following the retrieval of information from MongoDB and making it editable for the User

Currently, I store data in mongo for a multiple-choice question and indicate the correct answers. In mongo, I save them like this: question.options.option1.check = "on" for the correct answers. When I navigate to the "edit" page, I retrieve the specific ...

Using React.js to dynamically render routes with components based on JSON data

As a newcomer to react and the world of JavaScript, I find myself facing a challenge. I have a JSON file that contains URLs which I want to use in rendering specific components. { "MTs": { "MenuItems": { "Main": { "key": "1", "u ...

Has Apache initiated a forced logout process?

Running a LAMP server, I have implemented Apache basic authentication to log in users accessing the server homepage. I am currently seeking a way to enforce user logout, but my attempts with mod_session & mod_auth_form have not been successful. The page ...

Is it possible to run my JavaScript script immediately following the execution of npm run build?

Hey everyone! I am trying to run my JavaScript file right after receiving the successful message from npm run build. Currently, I am working on a Vue.js codebase. Is there a way for me to log and create a file in my code repository containing the 'run ...

AngularJS: The best practices for passing $scope variables to functions

Exploring the TodoMVC application has been a great way for me to enhance my skills with AngularJS. While delving into the index.html file, I stumbled upon lines 14-16 which contain the following code: <form id="todo-form" ng-submit="addTodo()"> ...

XPath in Selenium WebDriver version 2

Image of the code: https://i.sstatic.net/Tq2MF.png I am trying to find the label for Available Balance using the class FORM_NEW_ACCOUNT What is the correct way to write a Selenium xpath query for this? I have attempted multiple scenarios but none seem ...

Changing the color of a Highcharts series bar according to its value

Playing around with Highcharts in this plunker has led me to wonder if it's possible to dynamically set the color of a bar based on its value. In my current setup, I have 5 bars that change values between 0 and 100 at intervals. I'd like the colo ...

What is the functionality of the protection against AngularJS JSON vulnerability?

When working with JSONs in Angular, it is recommended to prefix them with )]}'\n for added protection against potential JSON vulnerability: A JSON vulnerability could allow a third-party website to transform your JSON resource URL into a JSONP ...

Discovering the Nearest Textfield Value Upon Checkbox Selection Using JQuery

How can I retrieve the value of the nearest Textfield after selecting a checkbox? This HTML snippet serves as a simple example. In my actual project, I have dynamically generated lists with multiple checkboxes. I require a way to associate each checkbox wi ...

Configuration failed: Maven was not able to run the @BeforeTest method for TestNG tests using Selenium

Hey there! I'm currently setting up my Selenium script with Maven and TestNG in Eclipse. To start, I simply right click on my project, select TestNG, then Convert to TestNG (which creates a testing.xml file). Next, I head over to Run Configurations t ...

How to iterate over the request body in Node.js using Express?

When I send a request with data in the form of an array of objects: [ {id: "1"}, {id: "2"}, {id: "3"} ] I am utilizing JSON.stringify() and my req.body ends up looking like this: { '{"id":"1"} ...

Combining strings with objects in Javascript: A step-by-step guide

In the code snippet provided, I am combining variables to create a path to another existing object and its attribute. The issue is that I always receive a string, but I would like to somehow convert it into an object. // SET CUSTOM CONTENT FOR COLUMN IF ...

How to enable Autocomplete popper to expand beyond the menu boundaries in Material UI

Within my Menu component, I have an Autocomplete element. When the Autocomplete is clicked, the dropdown list/Popper appears but it's confined within the Menu parent. How can I make it so that the Autocomplete's dropdown list/Popper isn't re ...

Link the asp control as you input text into the Text box

I currently have a situation where I am working with a text box and a repeater control. My goal is to dynamically bind the data to the repeater control as the user types into the text box, without requiring them to press the enter key or click with the mou ...

Navigating File Upload Using Python's Selenium on Ubuntu

I recently developed a Python script using Selenium to automate the process of uploading raw GPS data files to OPUS for my research project. While this script functions perfectly on Windows, I am currently facing issues while trying to execute it on a Linu ...

Removing slashes with the stripslashes() function causes the src to disappear once the iframe is

Here is the form I am working with: <form action="my_parse_file.php" name="myform" id="myform" method="post"> <input placeholder="Entry Title" style="height: 25px; text-align: center; font-size: 12px; background-color: #151515; color: #B4B4B4 ...

JQuery fixed div bounces unpredictably when scrolling

Currently, I have a scenario on my webpage where there is a div called RightSide positioned on the far right side below another div named TopBanner. The TopBanner div remains fixed at the top of the screen even when the user scrolls down, which is exactly ...