$-\nabla \cdot (A\nabla u)=f$ has a weak solution in $H^1$ $\iff$ $\int_\Omega f+\int_{\partial \Omega }g=0$. Let $\Omega \subset \mathbb R^d$ a smooth bounded connected domain of $\mathbb R^d$. Let $A$ symmetric and uniformly elliptic matrix defined on $\Omega $. Let $f\in L^2(\Omega )$ and $g\in H^{-1/2}(\partial \Omega )$. Prove that $$\begin{cases}-\nabla \cdot (A\nabla u)=f&\Omega \\ A\nabla u\cdot \nu=g&\partial \Omega \end{cases}$$
has a unique weak solution in $H^1(\Omega )$ if and only if $$\int_\Omega f+\int_{\partial \Omega }g=0.$$

Let $X=\{u\in H^1(\Omega )\mid \int_\Omega  u=0\}$. The weak equation is given by
$$\int_\Omega A\nabla u\cdot \nabla v=\int_{\partial \Omega }gv+\int_\Omega  fv,\quad \forall v\in X.\tag{E}$$
Question 1
For the necessary condition it's written : assume (E). taking $v=1$, the claim follow. But what I don't understand is that such a $v$ is not in $X$, so how can we take $v=1$ and replace in (E) ? 
Question 2
For the existence and uniqueness, they do as follow : Set $$a(u,v)=\int_\Omega A\nabla u\cdot \nabla v, \quad \forall u,v\in H^1(\Omega )/\mathbb R,$$
and
$$F(v)=\int_{\partial \Omega }gv+\int_\Omega  fv,\quad \forall v\in H^1(\Omega ).$$
The claim follow from Lax-Miligram.
The set $H^1(\Omega )/\mathbb R$ is the space of $H^1(\Omega )$ function that are not constant. Why do we take $u,v\in H^1(\Omega )/\mathbb R$ and not simply in $X$ ?
 A: Your weak formulation (E) is not correct.
The correct weak formulation is: find $u \in H^1(\Omega)$, such that
$$
a(u,v) = \int_\Omega f \, v \, \mathrm{d}x + \int_{\partial\Omega} g \, v \, \mathrm{d}x
\qquad\forall v \in H^1(\Omega),$$
where the bilinear form $a$ is defined by using $A$.
Let us define the bounded, linear operators $L, I : H^1(\Omega) \to H^1(\Omega)'$ and the functional $F \in H^1(\Omega)'$ via
$$
\langle L u , v \rangle_{H^1(\Omega)',H^1(\Omega)} := a(u,v) \\
\langle I u , v \rangle_{H^1(\Omega)',H^1(\Omega)} := \int_\Omega u \, v \, \mathrm{d}x \\
\langle F , v \rangle_{H^1(\Omega)',H^1(\Omega)} :=  \int_\Omega f \, v \, \mathrm{d}x + \int_{\partial\Omega} g \, v \, \mathrm{d}x$$
for all $u, v \in H^1(\Omega)$.
Now, the weak formulation becomes
$$L u = F.$$
Further, it is easy to check (via Lax-Milgram), that $L + I$ is boundedly invertible. Moreover, $I$ is compact (via Rellich-Kondrachov).
Thus, $L$ is a Fredholm operator with index $0$.
Hence, $L u = F$ is solvable if and only if
$$ \langle F, v \rangle = 0 \qquad \forall v \in H^1(\Omega) \text{ with } L^* v = 0.$$
Now, $L^* v = 0$ implies that $v$ is a constant function. Thus,
$$ \langle F, 1 \rangle = 0 $$
is a necessary and sufficient condition for the solvability of the weak formulation and this is exactly your condition.
Finally, let me mention why (E) is always solvable.
It is easy to check that the solution of (E) does not change if $f$ is replaced by $f + c$ for any constant $c$.
By setting $c$ to the appropriate value, you can achieve the compatibility condition $\int f + \int g = 0$. However, the associated solution will not be a weak solution in $H^1(\Omega)$.
A: 
For the second question First observes that if $u$ is a solution then $u+c$ is also a solution. for every $c\in\Bbb R. $ 
  Indeed both spaces guarantee the uniqueness of the solution since the do not contain constant functions. In fact the coercivity of your bilinear form cannot holds true in $H^1$ that is the key point why one chose the space $X$ where the coercivity holds true within Poincaré-inequalty.
Note that the spaces $X$ and  $H^1(\Omega )/\Bbb R$ are equivalent. So it does not matter working in one of these spaces . Personally I prefer to work in the space $X$ rather than $H^1(\Omega )/\Bbb R$ . 

For the first question 
Assume your system has a solution $u$  that is 
$$\begin{cases}-\nabla \cdot (A\nabla u)=f&\Omega \\ A\nabla u\cdot \nu=g&\partial \Omega \end{cases}$$
then integrating both side of the first equation  directly over $\Omega$ leads directly (after making use of Green formula )to 
$$\int_\Omega f = \int_\Omega -\nabla (A\nabla u)= -\int_{\partial \Omega }A\nabla u\cdot \nu = -\int_{\partial \Omega }g$$
Which give $$\int_\Omega f +\int_{\partial \Omega }g=0$$
Now Assume that $$\int_\Omega f +\int_{\partial \Omega }g=0$$  Since the variational formulation has a solution in X that is
$$\int_\Omega A\nabla u\cdot \nabla v=\int_{\partial \Omega }gv+\int_\Omega  fv,\quad \forall v\in X.\tag{E}$$
Whereas for every $w\in H^1(\Omega)$ we have $w=u+c$ with $u\in X$ and c is a constant. Since $$c\int_\Omega f +c\int_{\partial \Omega }g=0$$
Adding this To  (E) it is easy to obtain:
$$\int_\Omega A\nabla u\cdot \nabla v=\int_{\partial \Omega }gv+\int_\Omega  fv,\quad \forall v\in H^1(\Omega).\tag{1}$$
Hence u is also a solution to the original equation.
