Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey, I writes a program for adding sales post to a marketplace. In C #. I wonder how I can add a photo to this sales post. Maybe some path? I say right away that I don't want to use the API yet. I can choose this photo manually, but I want everything done automatically. I will be grateful for any help.

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;


namespace Marketplace
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string url = "https://www.facebook.com/";

        ChromeDriver driver; Thread th;

        private void Form1_Load(object sender, EventArgs e)
        {
            ChromeOptions options = new ChromeOptions();
            options.AddArguments("--disable-notifications"); // to disable notification
            driver = new ChromeDriver(options);
            driver.Navigate().GoToUrl(url);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            driver.FindElement(By.XPath("//button[normalize-space()='Akceptuj wszystkie']")).Click();

            driver.FindElement(By.XPath("//input[@id='email']")).SendKeys("login");

            driver.FindElement(By.XPath("//input[@id='pass']")).SendKeys("password");

            driver.FindElement(By.XPath("//button[contains(text(),'Zaloguj się')]")).Click();

            //login

            driver.FindElement(By.XPath("//*[name()='path' and contains(@d,'M17.5 23.7')]")).Click(); Thread.Sleep(2000);

            driver.FindElement(By.XPath("//div[@class='j83agx80 cbu4d94t d6urw2fd dp1hu0rb l9j0dhe7 du4w35lb']//span[@class='d2edcug0 hpfvmrgz qv66sw1b c1et5uql lr9zc1uh a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d3f4x2em fe6kdd0r mau55g9w c8b282yb iv3no6db jq4qci2q a3bd9o3v lrazzd5p knomaqxo']//span[1]")).Click(); Thread.Sleep(2000);

            driver.FindElement(By.XPath("//span[contains(text(),'Przedmiot na sprzedaż')]")).Click(); Thread.Sleep(3000);

            driver.FindElement(By.XPath("//div[@class='s45kfl79 emlxlaya bkmhp75w spb7xbtv bp9cbjyn rt8b4zig n8ej3o3l agehan2d sk4xxmp2 rq0escxv pq6dq46d taijpn5t l9j0dhe7 tdjehn4e qypqp5cg q676j6op']//i[@class='hu5pjgll lzf7d6o1']")).Click(); // now i can choose a photo from my computer




        }
    }
}
Posted
Updated 7-Oct-21 3:38am
v3
Comments
Richard MacCutchan 25-Aug-21 9:28am    
You need to use the facebook API.
morrisschriss 12-Oct-21 7:39am    
Can you inspect the Upload photo button in the browser and copy/paste the HTML into your question

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