0

i wants to get the control for (start building) option in servicenow login page. i have tried something but its not working.kindly help me in this case.

IWebElement ele3= driver.FindElement(By.XPath("//span[@type='button'][text()='[Start Building']")); ele3.Click();

enter image description here

when i click inspect it shows this, not able to capture class, id or name.

This is the sample code i done for login to servicenow: WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));

    driver.Manage().Window.Maximize();
    driver.Url = "https://developer.servicenow.com";
    Thread.Sleep(3000);
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    var query = "return document.querySelector('dps-app').shadowRoot";
    query += ".querySelector('dps-navigation-header').shadowRoot";
    query += ".querySelector('dps-login').shadowRoot";
    query += ".querySelector('dps-button')";
    IWebElement elt = (IWebElement)js.ExecuteScript(query);
    elt.Click();wait.Until(ExpectedConditions.ElementExists(By.Id("username"))).SendKeys("email@toto.fr");
    wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("usernameSubmitButton"))).Click();
    var but = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("submitButton")));
    driver.FindElement(By.Id("password")).SendKeys("password");
    but.Click();
jessy mary
  • 61
  • 7
  • Can you share the login page URL here if possible? It will help people to replicate your issue – QualityMatters Nov 17 '21 at 12:31
  • This is the url (https://developer.servicenow.com/dev.do#!/home), i have done the login part passing email and password and sign in that is done after that needs to click on start building for that iam searching commands in c# – jessy mary Nov 17 '21 at 12:43
  • Now you will have to share the DOM where that element is appearing. You can do it by : CTRIL+SHIFT+I (Open developer tool) in browser-> Mouse hover to that element-> Right click- – QualityMatters Nov 17 '21 at 12:57
  • (). this is the one i found i have used class but it not working it shows no such element found. – jessy mary Nov 17 '21 at 13:04
  • Can you check with this xpath: //button[@label='Start Building ']//span . – QualityMatters Nov 17 '21 at 13:10
  • (xpath:) is showing error while typing. – jessy mary Nov 17 '21 at 13:21
  • (IWebElement ele4 = driver.FindElement(By.XPath: // button[@label='Start Building']//span); ele4.Click();). i have tried this but its showing error. – jessy mary Nov 17 '21 at 13:31
  • This element is inside shadow root, that's why it is not clicking on it. Please refer this question: https://stackoverflow.com/questions/56380091/how-to-interact-with-the-elements-within-shadow-root-open-while-clearing-brow – QualityMatters Nov 17 '21 at 13:36
  • IJavaScriptExecutor js1 = (IJavaScriptExecutor)driver; var query1 = "return document.querySelector('dps-app').shadowRoot"; query1 += ".querySelector('dps-home-auth-quebec').shadowRoot"; query1 += ".querySelector('dps-page-header').shadowRoot"; IWebElement elt1 = (IWebElement)js.ExecuteScript(query); elt1.Click(); -i have tried this but its not working could someone help me in this case. – jessy mary Nov 17 '21 at 14:41
  • Do you have a demo credentials handy for test? – undetected Selenium Nov 17 '21 at 15:53
  • @LydiaSahayam did you get the solution with the help of relevant links? – QualityMatters Nov 18 '21 at 08:25
  • @DebanjanB:i have attached the sample code i done for login after that i wnats to click on start building but this part showing error using shadow root also.kindly help me – jessy mary Nov 19 '21 at 05:10
  • @QualityMatters:i have attached the code which i tried using shadowroot links but its showing error. – jessy mary Nov 19 '21 at 05:10
  • IJavaScriptExecutor js1 = (IJavaScriptExecutor)driver; var query1 = "return document.querySelector('dps-app').shadowRoot"; query1 += ".querySelector('dps-home-auth-quebec').shadowRoot"; query1 += ".querySelector('span').shadowRoot"; IWebElement elt1 = (IWebElement)js.ExecuteScript(query); elt1.Click();- when i tried this i got a (object reference not set to an insance of an object.) – jessy mary Nov 19 '21 at 05:37
  • I have a python code working fine. for your issue Let me convert it to C# one. Or let me know if you can do it by your own. I can share python snippet here – QualityMatters Nov 19 '21 at 06:29
  • sure pls share if possible can you share it as c# code.many thanks – jessy mary Nov 19 '21 at 06:40
  • IJavaScriptExecutor js1 = (IJavaScriptExecutor)driver; var query1 = "return document.querySelector('dps-app').shadowRoot"; query1 += ".querySelector('dps-home-auth-quebec').shadowRoot"; query1 += ".querySelector('dps-home-section-content.-header').shadowRoot"; query1 += ".querySelector('dps-page-header').shadowRoot"; query1 += ".querySelector('dps-button.-round.-md.has-action.-external-action.has-button-and-icon')"; IWebElement elt1 = (IWebElement)js1.ExecuteScript(query1); elt1.Click(); -i tried this still getting error – jessy mary Nov 19 '21 at 06:40
  • can i get an ans pls. – jessy mary Nov 19 '21 at 11:50
  • 1
    This worked in C#: driver.FindElement(By.Id("submitButton")).Click(); System.Threading.Thread.Sleep(1000*20); IWebElement startButtonElement = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript("return document.querySelector('dps-app[now-id]').shadowRoot.querySelector('div > main > dps-home-auth-quebec').shadowRoot.querySelector('div > section:nth-child(1) > div > dps-page-header > div:nth-child(1) > button > span')"); System.Threading.Thread.Sleep(4000); startButtonElement.Click(); – QualityMatters Nov 19 '21 at 13:06
  • 1
    Let me know if above code doesn't work – QualityMatters Nov 19 '21 at 13:07
  • Thanks much i got my output.Thanks for the help@QualityMatters – jessy mary Nov 22 '21 at 08:41
  • Hii@quality matters at first time when i run the code it successfully runs but sencond time when i run this code its showing object reference not set to an instance of an object.could you help me in this case? – jessy mary Nov 22 '21 at 10:12
  • 1
    May be you have done some changes. Just copy paste again. – QualityMatters Nov 22 '21 at 13:18
  • its working now,thanks much for the help. – jessy mary Nov 23 '21 at 05:57

0 Answers0