1

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
   withCapabilities(webdriver.Capabilities.chrome()).
   build();


driver.get('https://www.tumblr.com/login');
driver.findElement(webdriver.By.id('signup_email')).sendKeys('my_username');
driver.findElement(webdriver.By.id('signup_password')).sendKeys('my_password');
driver.findElement(webdriver.By.id('signup_forms_submit')).click();

driver.wait(function(){
driver.get('https://www.tumblr.com/search/love+gifs');
},5000);

driver.wait(function(){
  driver.findElement(webdriver.By.id("post_control like")).click();
},1000);

driver.wait(function(){
  driver.findElement(webdriver.By.id("follow-text")).click();
},1000);

driver.quit();
<div class="post-info-post-tumblelog">
<div class="post-info-tumblelog">
<a class="follow_link worded-follow-button show-unfollow" data-subview="follow" href="/follow/pleasingpics" style="width: 41px;">
<div class="follow-text" title="Follow">Follow</div>
<div class="unfollow-text" title="Unfollow">Unfollow</div>
</a>
</div>
</div>

I have a Javascript code for following some accounts on Tumblr using Selenium WebDriver.

In the HTML code, there is a follow button as you can see in a class named "follow-text". But my code doesn't work, also I'm wondering that follow button is not actually a button but they've made it a clickable div class. I'm not so familiar with HTML/CSS and I'm new with Javascript and Selenium Webdriver. What's wrong with my code? Also I have to click follow buttons on different posts on the same page. I'm thinking of creating a loop but I can't even click one of them. Any help will be appreciated.

3
  • 1
    Not to be the buzzkill here, but pretty sure this would be violating Tumblr's T's & C's: "... or overloading the Services, or by scripted use of the Services in such a manner as to interfere with or create an undue burden on the Services." - 1 follow every second could be deemed spammy/a burden. Commented Nov 29, 2015 at 2:15
  • I don't know the terms & conditions but this is a part of my internship program, that's why I'm doing it because it's important for me. Time between actions could be longer than 1 sec but anyway, thank you for your comment. Commented Nov 29, 2015 at 2:20
  • If it's an internship, and they're asking you to do that either knowingly violating rules, or unknowingly - that's a bad sign. Commented Nov 29, 2015 at 2:22

2 Answers 2

2

driver.wait(function(){
  var followButton = driver.findElement(webdriver.By.xpath("/html/body/div[4]/div/div/div[2]/div[2]/div[1]/div[2]/div/article[5]/header/div/div/div/a/div[1][@class='follow-text']"));
  followButton.click();
},1000);

This code solved my problem. I guess firebug's xpath selector gave the wrong answer to me. I changed it a lot and finally it worked. Thank you all for your help.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to click on the parent element. Not on the div, but to the <a> -- as parent of div.

11 Comments

I've tried to click the part starting with <a class="...." but it didn't work either. driver.wait(function(){ driver.findElement(webdriver.By.className("follow_link worded-follow-button show-unfollow")).click(); },1000);
its because of Selenium dont work with compilations of classnames. you need to search by xpath or by "follow_link" only
@ÇağatayBarın did you fix the issiu?
nope, I'm trying different things like By.className or By.xpath or By.cssSelector but it's not working :(
@ÇağatayBarın by class "follow_link" will work for you =) try it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.