0

I am trying to automate a website with Selenium, however GetAttribute is behaving weirdly. Whatever element I try to getattributes, I get the error below. I am not sure why it would be trying to get something from the System.IO.

I isolated the code, tried using IWebDriver and ChromeDriver, nothing worked.

ChromeDriver chrome = new ChromeDriver(Util.Util.GetHomeDir() + "/eztools/drivers/");
chrome.Navigate().GoToUrl("https://dfe-portal.svrs.rs.gov.br/NFE/CCC");
Thread.Sleep(5000);
IWebElement el1 = chrome.FindElementById("CodUf");
Log.Debug("el1:" + el1);
Log.Debug("el2:" + el1.TagName);
Log.Debug("el2:" + el1.GetAttribute("data-val"));

Error:

em System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   em System.IO.Path.InternalGetDirectoryName(String path)
   em OpenQA.Selenium.Internal.FileUtilities.GetCurrentDirectory()
   em OpenQA.Selenium.Internal.ResourceUtilities.GetResourceStream(String fileName, String resourceId)
   em OpenQA.Selenium.Remote.RemoteWebElement.GetAtom(String atomResourceName)
   em OpenQA.Selenium.Remote.RemoteWebElement.GetAttribute(String attributeName)
   em ezrpa_runner.Cmds.Logic.WebCaptcha.run(CommandDomain cmd) na C:\ez\vs2019\ez-inspect\ezrpa-runner\Cmds\Web\WebCaptcha.cs:linha 44
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Geovane
  • 31
  • 2

1 Answers1

0

The desired element is a dynamic element, so to locate the element you have to induce WebDriverWait with ExpectedConditions set as ElementToBeClickable() and you can use either of the following Locator Strategies:

  • Using Id:

    //IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.Id("CodUf")));
    //Incase you are using Nuget
    IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id("CodUf")));
    Log.Debug("el1:" + el1);
    Log.Debug("el2:" + el1.TagName);
    Log.Debug("el2:" + el1.GetAttribute("data-val"));
    
  • Using Name:

    //IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.Name("CodUf")));
    //Incase you are using Nuget
    IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Name("CodUf")));
    Log.Debug("el1:" + el1);
    Log.Debug("el2:" + el1.TagName);
    Log.Debug("el2:" + el1.GetAttribute("data-val"));
    
  • Using CssSelector:

    //IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("select[name='CodUf']")));
    //Incase you are using Nuget
    IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector("select[name='CodUf']")));
    Log.Debug("el1:" + el1);
    Log.Debug("el2:" + el1.TagName);
    Log.Debug("el2:" + el1.GetAttribute("data-val"));
    
  • Using XPath:

    //IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//select[@name='CodUf']")));
    //Incase you are using Nuget
    IWebElement el1 = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//select[@name='CodUf']")));
    Log.Debug("el1:" + el1);
    Log.Debug("el2:" + el1.TagName);
    Log.Debug("el2:" + el1.GetAttribute("data-val"));
    

Reference

You can find a relevant discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi @DebanjanB, still the same issue. On further investigation, I figured Webdriver uses a small "Atom" as they call it to handle it using Javascript executor. Weird thing is that this is the default package from Nuget, so not sure why it is not being able to load this getattribute Atom. That is it throws an issue related to open a file from system path. – Geovane May 23 '20 at 19:19
  • @Geovane Checkout the updated answer and let me know the status. – undetected Selenium May 23 '20 at 19:42