1
I would like to know how to press the follow button of Instagram with Selenium, I have tried several ways and none I can press. Always says or that the element is not clickable or cannot find the element.
<span class="vBF20 _1OSdk"><button class="_5f5mN jIbKX _6VtSN
yZn4P ">Seguir</button></span>
This is the code of the button I want to click. I have tested it in the following ways.
driver.FindElement(By.CssSelector("button")).click()
driver.FindElement(By.ClassName("_5f5mN jIbKX _6VtSN yZn4P")).Click()
((IJavaScriptExecutor)driver).ExecuteScript("document.getElementsByClassName('_5f5mN jIbKX _6VtSN yZn4P')[0].click()");
I no longer know what to try ... someone knows how to do ? ...
NOTE: This last one works in the browser if I play on the console. But when I try for Selenium it does not find the Element to click.
NOTE: I tested the following codes below and also did not work
((IJavaScriptExecutor)driver).ExecuteScript("document.getElementsByTagName('button')[1].click()");
driver.FindElement(By.XPath("\\button:text()="Seguir"[1]")).Click();
((IJavaScriptExecutor)driver).ExecuteScript("document.evaluate(\"//button[text()='Seguir'][1]\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click()");
tries to swap xpath for //button[text()='Follow'][1] , this css ai looks like it is named dynamically
– Lucas Miranda
Question, is it for testing or for bot?
– Leandro Angelo
I’m testing and at the same time making a bot too. Lucas, I’ll test here and I’ll tell you if it worked.
– Diasz
Lucas Miranda unfortunately did not work the method he passed with xpath. https://prnt.sc/uu8i7n
– Diasz
a new attempt, try using the script executor to run it here Document.evaluate("/button[text()='Follow'][1]", Document, null, Xpathresult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click()
– Lucas Miranda
I’ll test and get back to you
– Diasz
Unfortunately it was an error - https://prnt.sc/uubv4s
– Diasz
((Ijavascriptexecutor)driver). Executescript("Document.evaluate("//button[text()='Follow'][1]", Document, null, Xpathresult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click()"); that is the code .. It seems that Instagram won’t let the bot run .. pq by the console in the browser worked...
– Diasz