使用watir的ruby中的语法错误

时间:2018-04-26 07:13:54

标签: ruby watir

enter image description here

我正在制作一个继续使用Instagram并转发给某人的程序。我没有看到任何错误,但当我运行它时,它说语法错误意外tSTRING。 我抬起头来,无法完成我做错的事。

如果有人可以帮助我。 THX

require 'watir'

username = "videos2fdp"
password = "no pass"
user = "videos_folle"

browser = Watir::Browser.new :chrome
browser.goto"https://www.instagram.com/accounts/login/"

puts "Logging in ..."
browser.text_field(:name => "username").set"#{username}"
browser.text_field(:name => "password").set"#{password}"

browser.button(:class => '_ah57t _84y62 _i46jh _rmr7s').click
sleep(2)

browser.goto "instagram.com/#{user}/"

if browser.button(:class => '_ah57t _84y62 _frcv2 _rmr7s').exist ?
    puts "Following #{user}"
    browser.button(:class => '_ah57t _84y62 _frcv2 _rmr7s').click
end


sleep (3)

if browser.button(:class => '_ah57t _6y2ah _frcv2 _rmr7s').exist ?
    puts "Unfollowing #{user}"
    browser.button(:class => '_ah57t _6y2ah _frcv2 _rmr7s').click

end






sleep(360)

1 个答案:

答案 0 :(得分:2)

好的,这是更正的代码,立即尝试

您错误放置?而不是exist?正在使用exist ?

require 'watir'

username = "videos2fdp"
password = "9519516477Am"
user = "videos_folle"

browser = Watir::Browser.new :chrome
browser.goto "https://www.instagram.com/accounts/login/"

puts "Logging in ..."
browser.text_field(:name => "username").set "#{username}"
browser.text_field(:name => "password").set "#{password}"

#browser.button(:text => 'Log in').click
browser.button(:class => "_qv64e       _gexxb _4tgw8     _njrw0   ".split).click
sleep(2)

browser.goto "instagram.com/#{user}/"

if browser.button(:class => '_ah57t _84y62 _frcv2 _rmr7s'.split).exist?
  puts "Following #{user}"
  browser.button(:class => '_ah57t _84y62 _frcv2 _rmr7s'.split).click
end


sleep (3)

if browser.button(:class => '_ah57t _6y2ah _frcv2 _rmr7s'.split).exist?
  puts "Unfollowing #{user}"
  browser.button(:class => '_ah57t _6y2ah _frcv2 _rmr7s'.split).click

end


sleep(360)