0

I noticed some results of call to GetAttribute provide not fully decoded strings.

var element = driver.FindElement(By.CssSelector($"#lien_batiment_{id}"));
var href = element.GetAttribute("href");

Actual:

"javascript:f_affiche_contenu(9367718,'coopr_detail_batiment.php?id=9367718&filtre=32&contenuonly=1%27);"

Expected:

"javascript:f_affiche_contenu(9367718,'coopr_detail_batiment.php?id=9367718&filtre=32&contenuonly=1');"

If it was normal, first apostrophe should have been encoded too, and probably & too.

Expected value is provided as well by chrome developper panel. Edge provide the same, and it almost seems logic to have correct decoded JS to execute it with IJavaScriptExecutor.

I use a href= href.Replace("%27","'"), but it's not a serious option if I have js containing real decode %27 sequence.

Any Idea ?

Dependencies :

  • Selenium.WebDriver.ChromeDriver 103.0.5060.13400
  • Selenium.WebDriver 4.3.0
  • Selenium.Support 4.3.0
  • .Net Framework 4.8

here some more informations to reproduce :

var chromeOptions = new ChromeOptions();
var driverService = ChromeDriverService.CreateDefaultService();

using(var driver = new ChromeDriver(driverService, chromeOptions))
{
   driver.Navigate().GoToUrl("https://france2.simagri.com/");
   // have to login with account here
driver.FindElement(By.Name("Login")).SendKeys("login");
driver.FindElement(By.Name("Password")).SendKeys("password");
driver.FindElement(By.Name("FAccesCompte")).Submit();

driver.Navigate().GoToUrl("https://france2.simagri.com/liste_batiment.php");
   // you need to have some batiments 
   var id = 9132371; // feed matching one

   var element = driver.FindElement(By.CssSelector($"#lien_batiment_{id}"));
var href = element.GetAttribute("href");

}

as you can see, very simple...

  • If it's the expected value in chrome console, use execute_script to get it. You can always expect chrome to behave more properly than selenium – pguardiario Aug 01 '22 at 04:19
  • it doesnt change anything. really interesting... as JS script works on the website, then I suppose Chrome have a lazy mechanism. I noticed it monthes ago copying outer-html from developper tool with some not decode attribute, but I didnt expect API's will suffer the same problem – Bourriquet Aug 01 '22 at 09:12
  • You'd have to post some code. It sounds like you're probably doing something silly. – pguardiario Aug 01 '22 at 09:24
  • I added at end of post. good chance with something silly :) – Bourriquet Aug 01 '22 at 14:25

1 Answers1

0

Presumably you need to wait a bit for the element to completely render before you extract the href attribute inducing WebDriverWait for the _ElementIsVisible_as follows:

var href = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementIsVisible(By.CssSelector($"#lien_batiment_{id}"))).GetAttribute("href");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • it doesnt change anything. If asynchronous work is the origin of problem, it's probably not at Selenium level. I'll try with more browsers to have an idea – Bourriquet Aug 01 '22 at 09:03