Search code examples
htmlgoogle-chromewatirwatir-webdrivergoogle-groups

Access table cell values within Google Groups Member page using Watir


I am looking to access table data within a webpage that seems to be harder to reach than other methods I've seen posted. I am concerned that some of the HTML is visible to Watir because if you save the page as an HTML file, the table and its data are not included.

Here's the situation: Google Groups has a member list (when you are viewing the settings as a Group admin). I want to find (or iterate) through the table, looking to match an email address. When that is found, I would select the row (checkbox), which enables the 'Actions' menu. From the actions menu, I would update the Delivery settings to 'No email'.

I've attached a screenshot of the members page as well as a snippet of the HTML.

Please post suggestions/answers specific to Google Groups tables. I've tried 6+ other approaches that work on simpler HTML pages, but not on Google Groups.

Thanks

HTML (img)

Here's a screenshot of the menu I am trying to access. Actions popup menu (img)

Before and after when click on the 'Actions' menu button to get the hovering menu.

Before

<div tabindex="0" role="button" class="IVILX2C-n-a jfk-button-standard IVILX2C-k-c" aria-haspopup="true" aria-controls="gwt-uid-809" aria-expanded="false" aria-disabled="false" data-title="Actions">

After

<div tabindex="0" role="button" class="IVILX2C-n-a jfk-button-standard IVILX2C-k-c IVILX2C-n-a-selected IVILX2C-n-j" aria-haspopup="true" aria-controls="gwt-uid-809" aria-expanded="true" aria-disabled="false" data-title="Actions" aria-activedescendant="gwt-uid-819">

Note, the "gwt-uid-xxx" value is not consistent between sessions.

Update: These three lines seem to work to click the 'Actions' menu, hover over 'Change delivery settings', and click 'No email'

@driver.element(text: 'Actions').click
@driver.element(text: 'Change delivery setting').hover
@driver.div(class: 'popupContent', index: 1).div.div.div(text: 'No email').click

EDIT: Code below

require 'rubygems'
require 'watir-webdriver'
require 'logger'
require 'csv'

def setup
  @driver = Watir::Browser.new :chrome

  # set the timeout for implicit waits
  @driver.driver.manage.timeouts.implicit_wait = 5

  #Create log file
  if @logger.nil?
    @logger = Logger.new( 'D:/Google Drive/_code/GroupsEmailSetting/ChangeDeliverySetting_log.txt',10)
    @logger.level = Logger::DEBUG
    @logger.datetime_format = '%Y-%m-%d %H:%M:%S%z'
  end

  #admin credentials
  @login_user = '[email protected]'
  @login_pwd = 'pwd!'

end

def teardown
  puts "Enter to close"
  a = gets.chomp
  @driver.quit
  @logger.close
end

def run
  setup
  yield
  teardown
end

run do

  @driver.goto "https://accounts.google.com"
  element = @driver.text_field(:id => "Email")
  element.send_keys(@login_user)
  @driver.button(:id => "next").click
 
  element = @driver.text_field(:id => "Passwd")
  element.send_keys(@login_pwd)
  @driver.button(:id => "signIn").click

  @logger.info "User logged in: #{@user}"


  #TEMP # find users, change email setting
  @domain = 'domain.com'
  @group = 'watir_table'
  @user = '[email protected]'
  @dsetting = 'No email'
  @logger.info("Group & User selected: #{@group + "@" + @domain + " : " + @user}")

  #END TEMP
  @driver.goto "https://groups.google.com/a/domain.com/forum/#!managemembers/#{@group}/members/active"


  @logger.info "Group loaded: #{@group}"

  browser.span(text: '[email protected]').parent.parent.checkbox.click

end


Solution

  • This is a pretty common pattern and it would be nice if we had a better way to address it. Try something like this:

    [email1, email2, email3].each do |email_address|
        row = @driver.div(text: email_address).parent.parent
        row.checkbox.click
        row.div(text: 'All email').parent.parent.checkbox.click
    end
    
    browser.element(text: 'Change delivery setting').hover
    browser.element(text: 'No email').click