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...