Click here to Skip to main content
15,029,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Dear Helpers
my program works as windows form
I Have one error help me pls

My code
private void çek_Click(object sender, EventArgs e)
        // Image image = Image.FromFile(@"C:\Users\Sau\Desktop\Dmp-Wr6WwAEQPtp.jpg");

         IWebElement element = driver.FindElement(By.Id("gsc_prf_pup-img"));
        String src = element.GetAttribute("src");

        label5.Text = src;


        var request = WebRequest.Create(src);

        using (var response = request.GetResponse())
        using (var stream = response.GetResponseStream())
            profil.Image = Bitmap.FromStream(stream);


ERROR Message:
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"css selector","selector":"#gsc_prf_pup\-img"}
  (Session info: chrome='


What I have tried:

Try 1
var element = driver.FindElement(By.TagName("img"));
string imageSrc = element.GetAttribute("src")

Try 2
IWebElement logo = driver.findElement(By.cssSelector(".forum-logo"));
   String logoSRC = logo.getAttribute("src");
Updated 29-Jul-20 21:34pm
Sandeep Mewara 30-Jul-20 3:32am
1. What is the image name in actual that is there in your application?
2. How is that referred in your code? Believe somewhere in User interface (UI) - it would help others with that code.

For now, app is unable to find the image element the way you are trying to access it.

1 solution

I guess the error message is quite clear, it can't locate the element (try working on a system where there were no unique id's/tags etc... bleh) .. try using something like Ranorex Selocity (it's free), install it in Chrome and use it to identify the element - it can suggest a couple of methods for the locator if I remember correctly

Disclaimer : I'm not associated with Ranorex in any way except for a grateful user of one of their tools, no $$ under the table for recommendations
CL4Y3R-TR 30-Jul-20 3:42am
It worked when I tried this code in c # console
CL4Y3R-TR 30-Jul-20 3:43am
but I have to work in windows form
CL4Y3R-TR 30-Jul-20 3:59am
Thank you i solved problem :)
Garth J Lancaster 30-Jul-20 4:32am
good - you can still use tools like Selocity to give you the element to use from a Winform app or whatever - you're using a Winform app to drive Selenium, that's the critical part here

Glad you figured it out anyway

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900