0

I have a front page with Clients which I should click on 3dots for a specific client in my script. But after I have clicked on a save button on one of the tabs which brings me back to the grid cell it takes to long and cannot find the 3dots.

Element:

<td role="gridcell">
    <a class="btn btn-default" href="/configuration/clientmanagement?Id=352">
        <i class="fa fa-ellipsis-v"></i>
    </a>
</td>

My code:

//User selects Client to add details
[Then(@"user clicks on the configure dots icon for Client (.*) for main flow")]
[Obsolete]
public void ThenUserClicksOnTheConfigureDotsIconForClientForMainFlow(string ClientId)
{
    Thread.Sleep(5);
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
    wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div/main/div/div[2]/div/div/div[2]/table/tbody/tr[3]/td[4]/a")));
    Actions action = new Actions(driver);
    action.MoveToElement(driver.FindElement(By.XPath("/html/body/div/main/div/div[2]/div/div/div[2]/table/tbody/tr[3]/td[4]/a"))).Build().Perform();
    IWebElement ConfigureDots = driver.FindElement(By.XPath("/html/body/div/main/div/div[2]/div/div/div[2]/table/tbody/tr[3]/td[4]/a/i"));
    ConfigureDots.Click();
    Console.WriteLine("Client selected: " + ClientId);
}
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • 1) You can't click plain text. You need to find and click the `a` element. 2) absolute paths are *extremely* fragile and guaranteed to break after the smallest change. It would be best if the tag had an `id` or `name` which would allow you to find it by ID. Witthout it, you can find all `a` tags with the `btn-default` class if you use `"//a[contains(@class, 'btn-default')]"` or `//a[@class='btn btn-default']` – Panagiotis Kanavos Feb 25 '21 at 07:05
  • You can search using XPath or CSS in your browser's [Developer Tools](https://testerlive.wordpress.com/2016/07/02/how-to-search-by-xpathcss-in-chrome-developer-tools/). In the Elements tab you can hit Ctrl+F and search eg for `//td[@role='gridcell']` to find all gridcell cells, `//tbody/tr[3]/td[@role='gridcell'][4]` to find a specific cell or `//tbody/tr[3]/td[@role='gridcell']/a[@class='btn btn-default']` to find the link – Panagiotis Kanavos Feb 25 '21 at 07:16
  • If you want to test an entire grid though, you probably don't want a specific row, so you can use `FindElements` with `//tbody//td[@role='gridcell']/a[@class='btn btn-default']`. If the table has an ID, name or a unique class, you can find the *table*, then use `FindElements` on the table element to find children, eg `var table=driver.FindElementById(tableId); var links=table.FindElements(By.XPath("//tbody//a[@class='btn btn-default']"));` – Panagiotis Kanavos Feb 25 '21 at 07:23
  • If you want to click the `a` tag with that specific `href`, you can use use `//a[@href='/configuration/clientmanagement?Id=352']` – Panagiotis Kanavos Feb 25 '21 at 07:25
  • I agree. This is an example of the gridcell. I can only click on the dots to configure. So you mean the dots should have an element id, cause currently it can only be searchable by XPath. ID Name DisplayName Description 1 Peter Peter White Peter White ⁞ 2 Jack Jack Robinson Jack Robinson ⁞ – Anneline Van Der Merwe Feb 25 '21 at 07:27
  • The problem is after clicking on a Save button on one of the tabs it returns to the grid and most of the time it takes to long for the grid cell to show and then the click on a specific href fails. I have put several waits in as you can see in my code. Is there something else I can use that will definitely works. – Anneline Van Der Merwe Feb 25 '21 at 07:41
  • You'll have to wait for longer. `wait.Until` doesn't wait forever. The answers to [this question](https://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present) show how to increase the timeout or [use the WaitHelpers packge](https://stackoverflow.com/questions/49866334/c-sharp-selenium-expectedconditions-is-obsolete/49867605#49867605) and ExpectedConditions – Panagiotis Kanavos Feb 25 '21 at 07:50
  • I found that Thread.Sleep(1000), works perfectly. – Anneline Van Der Merwe Feb 25 '21 at 08:55
  • That's a 1 sec wait. I think the default for WebDriver is 500ms. If you expect the site to be that slow you can change the default timeout instead, with `driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1);` – Panagiotis Kanavos Feb 25 '21 at 08:59
  • Thanks will try that – Anneline Van Der Merwe Feb 25 '21 at 09:12
  • The driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1) does not working so efficient as Thread.Sleep(1000); – Anneline Van Der Merwe Feb 25 '21 at 09:31
  • Please [edit] your question to include the error message and stack trace. – Greg Burghardt Feb 25 '21 at 19:02
  • What do you mean by "it takes to long to find the 3 dots"? Are you getting an error? What is the message and stack trace? Please add that to your question. – Greg Burghardt Mar 05 '21 at 18:16
  • What I mean is after saving a record which takes me back to the grid takes to long to display the grid, the grid doesn't show in time to click again on the 3 dots again. The is no errors only that it doesn't see the 3 dots. – Anneline Van Der Merwe Mar 08 '21 at 06:13
  • Are you getting a "NoSuchElementException" then? This sounds like a race condition between Selenium executing the step and the browser doing stuff. – Greg Burghardt Mar 08 '21 at 19:26

0 Answers0