To factor $ x^2+ax+bx+ab $ we can use factoring by grouping.
Group $ \color{blue}{ x^2 }$ with $ \color{blue}{ ax }$ and $ \color{red}{ bx }$ with $ \color{red}{ ab }$ then factor each group.
$$ \begin{aligned} x^2+ax+bx+ab &= ( \color{blue}{ x^2+ax } ) + ( \color{red}{ bx+ab }) = \\ &= \color{blue}{ x( x+a )} + \color{red}{ b( x+a ) } = \\ &= (x+b)(x+a) \end{aligned} $$