Locating an element with the help of specflow and selenium

Having trouble locating the Google login button on this URL:

Encountering a NoSuchElementException while using Specflow to simply open the browser, navigate to the URL, and click the button.

Below is a snippet of the code being used:

_driver = new EdgeDriver();
_driver.Manage().Window.Maximize();
_driver.Url = "https://marketsmithindia.com/mstool/landing.jsp#/signIn";
Thread.Sleep(3000);

//code to handle terms and conditions dialog
var element = _driver.FindElement(by: By.XPath("//*[@id=\"msi_non_eu_popup\"]/div/div/div[3]/button"));
  if (element != null)
  {
      element.Click();
  }
Thread.Sleep(5000);
//exception occurs at this line when trying to locate Google button element
var googleButtonElement=_driver.FindElement(By.XPath("//*[@id='googlebtnclick']"));

Your assistance or suggestions on how to resolve this issue would be greatly appreciated.

Answer №1

To access elements inside a shadow root in the DOM, it's recommended to use the GetShadowRoot method.

driver
     .FindElement(By.Id("loginButton"))
     .GetShadowRoot() <-- This will provide you with the shadow root context
     .FindElement(By.Id("submitBtn"));

Answer №2

The google login button is hidden within the Shadow DOM. Accessing this element requires navigating through the shadow-root first.https://i.stack.imgur.com/gpHis.png

To interact with the button, you can utilize the JavasciptExecutor and execute the following query.

IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;
var googleButtonElement = js.ExecuteScript("return document.querySelector('user-login').shadowRoot.querySelector('#googlebtnclick');");

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

Converting Windows Identifiers to Human-Readable Text with the Power of Selenium and Python

I am aware that in order to retrieve the corresponding IDs of the currently open windows, I utilize the following code snippet in Python: current_windows = driver.window_handles print(current_windows) Output (assuming there are 2 open windows): ['CDw ...

Using Selenium and Python, I will demonstrate how to choose a kendo dropdown element that has the unselectable="on" attribute

Having trouble selecting the kendo dropdown with the provided code snippet. Feel free to visit the site and review the code. <span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input">Chang</sp ...

What is preventing the send_keys function from working in the comment box?

I'm currently working on a project to develop an automated Instagram bot that will comment on posts in my feed. However, I've encountered an issue when trying to input text into the comment box using the send_keys method. While setting up the log ...

How do I retrieve the file name from a PHP download URL?

I am currently working on a C# program that uses the webbrowser control to access my university's Moodle platform. I found some code online in the form of CookieAwareWebClient.class which helps me download authorized files. However, I am facing an iss ...

What are the possible reasons for the Selenium GECKO driver failing to start the server on Firefox 48?

In our .Net Automation Testing Project, we were using Selenium 2.5.3 along with a NUnit Test project successfully with Firefox version 47. However, after upgrading to Firefox 48, we started encountering issues. I downloaded the Gecko.exe (version 9) from ...

Untangling Internet JSON data

I am attempting to parse the JSON string into objects and then display it in a richtextbox public void Form1_Load(object sender, EventArgs e) { using (var webClient = new System.Net.WebClient()) { var json = webClient.Dow ...

An issue occurred while executing PhantomJS using Selenium's RemoteWebDriver

Launching a selenium grid hub using the default startup command: java -jar selenium-server-standalone-2.33.0.jar -role hub Also, initiating PhantomJS in its webdriver mode on the same machine with the following command: phantomjs --webdriver=8080 --web ...

Issue with the functionality of Selenium translate class in C#

I have developed a C# class that utilizes selenium to open a website and translate input text. This class is integrated into my project for translation purposes. Instead of using an API, I opted for the website's translation service as it allows me t ...

Issues arise when working with the variable Webdriver driver in conjunction with PageObjects

Is there a way to optimize the usage of Login_Page Login = PageFactory.initElements(driver, Login_Page.class) in all steps? It seems to be causing an error when used for each step as Java shows the message: "Value driver is always 'null'". I am ...

Sending a JavaScript array to an MVC controller in .NET 5.0 via a POST request

Trying to send data from a JavaScript array to an MVC controller. While debugging, I end up in the method public void GetJSArray(List<SelectorModel> selectorModels) However, the selectorModels is currently showing as null. Below is the model being ...

Saving a targeted image with C# Selenium Webdriver no matter its whereabouts

There are many examples of how to save an image by taking a screenshot, but this method has a major flaw. The issue is that the screenshot only captures what is visible on the page at that moment. So, if there is an image at the bottom of the page and you ...

Is it possible to combine a string with a dynamic value in-line?

Looking to retrieve values from a JSON object dynamically? Here's an example: var valueOne = jsonObj.features[0].properties.POLYGON_NM.ToString(); If you want to collect multiple values without manually typing each option, you can use a syntax like ...

Switch _ Click on it is required in python using selenium

I'm attempting to create an xpath for a toggle switch. Essentially, I need to click on the following element in order to toggle it: Actual HTML code <label class="" for="toggleResume" data-e2e="toggleResume"><s ...

The program cannot locate the reference to the 'NUnit' type or namespace

Recently, I encountered an issue with a c# code that was exported from Selenium IDE. using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using Selenium; namespace SeleniumTests { [TestFixt ...

Exclude element from test if text is present within the element in the table

Hey there! I have a question and I'm looking for some assistance ...

Selenium: The Hunt for the Absent Get Methods

When trying to use the GetAttribute or GetText methods in Selenium, I am unable to find them. For example, there is a Forgotten Password link with instructions above it to click the button if password is forgotten. I wanted to use GetText, but that option ...

Retrieving Information from JSON Response (C# with Windows Forms)

I'm having a bit of trouble extracting the street, town, and county from the JSON data retrieved using the Google Mapping API based on the postcode input. At the moment, I can successfully store the JSON data in a variable. However, I need help with ...

pursuing the team (without achieving the expected components)

My attempt to scrape data from a website using Selenium is facing an issue. Despite removing the text that contains "team," Selenium fails to detect this element. Why is it not grabbing all the elements following "team"? Is there a better way or a method l ...

Perform the action only when the record is fresh

Currently in my ASP.NET/C# project, I have implemented an AJAX Timer for periodic data retrieval from the backend. The code snippet I am using within the Timer Tick event handler looks something like this: Here is my code: OdbcDataReader dr = cmd.Execute ...

Having trouble getting selenium with pyvirtualdisplay to function properly on a DigitalOcean Ubuntu droplet

Despite having all the same software, this code snippet is not functioning on my digitalocean ubuntu droplet, yet it works perfectly fine on my local computer. It just seems to be hanging without any progress. import os from selenium import webdriver fro ...