1

browserContainer.EvaluateScriptAsync("document.querySelector('input[id=auth-modal-email]').value='****@gmail.com';");
browserContainer.EvaluateScriptAsync("document.querySelector('input[id=auth-modal-current-password]').value='*****';");
browserContainer.EvaluateScriptAsync("document.querySelector('button[type=submit]').click();");

I've been trying to login a website. I can see that id and password are being filled when I run the application and show it on panel. I also tried on BBC iplayer to understand whether it is related to javascript or not however it was working fine on BBC iplayer login screen.

The website: https://www.cars.com

Keyvan Soleimani
  • 606
  • 2
  • 4
  • 16

1 Answers1

0

The website uses custom html components. Some of the html elements within those custom components cannot be accessed directly. You first have to find the custom component and then work from there.

Here is code that works for the submit button in the login form (assuming the login form is visible):

document.querySelector('cars-auth-modal').shadowRoot.querySelector('ep-button').click();
NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • Thank you so much it works! However I have to login without opening the popup screen. How can I do that? – alper saraç Dec 25 '22 at 00:13
  • You can just open the url https://www.cars.com/signin/ and use the form there. The inputs have different names but there are no custom html components so that your code should work if you just adapt the names of the inputs – NineBerry Dec 25 '22 at 11:40
  • This is exactly what I did thank you again. I am now trying to select filters on homepage. I managed to select price, distance, zip and new/used however I couldn't select make and model I think because those components use optgroup under select-option. This is how I try. browserContainer.EvaluateScriptAsync("document.getElementById('makes').value = 'tesla';"); browserContainer.EvaluateScriptAsync("document.getElementById('models').value = 'tesla-model_s';"); – alper saraç Dec 25 '22 at 11:59
  • Please ask a new question when you have a different problem – NineBerry Dec 25 '22 at 13:28
  • Thank you for the response. I asked a new question in here. https://stackoverflow.com/questions/74913640/cefsharp-doesnt-select-option-value – alper saraç Dec 25 '22 at 13:47