I facing problem open dropdown select option on click in c# using selenium

Viewed 222

I am trying to open the Register page from my account. The UI developer used the bootstrap code. Bootstrap developers have added the JS function on click. and when I run this code then show error "OpenQA.Selenium.ElementClickInterceptedException has been thrown

element click intercepted: Element ... is not clickable at point (984, 50). Other element would receive the click: ... (Session info: chrome=77.0.3865.120)"

Attached Screenshot link: https://monosnap.com/file/1z5PYCFBHfcXtkWJWVMi4SeejUXXOf https://monosnap.com/file/hdq3194312RCnvc6GdQXLLVqtoezNJ

This my code

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace XTSeleniumtest
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");

            driver.FindElement(By.CssSelector("div.modal-header .close")).Click();
            driver.FindElement(By.XPath("//a[@id='navbarDropdown']/u")).Click();


        }
    }
}
**`

> strong text

`**
2 Answers

You can wait until the element is visible.

driver.FindElement(By.XPath("//a[@id='navbarDropdown']/u"));

If still the issue exists please post the DOM structure of your web page,it may be related to interacting with a wrong element.

Try the below code. You would need to add reference for "SeleniumExtras.WaitHelpers" from nuget

 class MainClass
    {
        public static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://freshpicksdev.isrv.tech/");
            driver.FindElement(By.CssSelector("div.modal-header .close")).Click();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//u[contains(text(),'My Account')]")));
            driver.FindElement(By.XPath("//u[contains(text(),'My Account')]")).Click();
            driver.FindElement(By.XPath("//a[text()='Register']")).Click();
        }
    }
Related