Skip to content

modified ruby locator code - #2993

Open
rpallavisharma wants to merge 15 commits into
SeleniumHQ:trunkfrom
rpallavisharma:rubyLoc-pal
Open

rpallavisharma wants to merge 15 commits into
SeleniumHQ:trunkfrom
rpallavisharma:rubyLoc-pal

Conversation

@rpallavisharma

@rpallavisharma rpallavisharma commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

fixes the ruby code by making it executable as with respect to other bindings. fixes #2952

Motivation and Context

the ruby code earlier just holded elements information didn't do anything.

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

@netlify

netlify Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

👷 Deploy request for selenium-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit f8a85cf

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@rpallavisharma

Copy link
Copy Markdown
Member Author

@aguspe can you please help in here to fix this. i don't understand the error. i see its generated because of relative locators. let me know what to fix. thanks.

@aguspe

aguspe commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Hi @rpallavisharma !

So the error is not really your code, the problem is that locators.html doesn't have any of the elements the relative locators use as anchors (password, email, cancel, submit, lbl-email), so Chrome can't find them and you get that weird call function result missing int 'status' error

I fixed it locally by overriding the url inside the relative locators context with a small login form, that way the outer before loads it and we can check the actual element we get back:

  context 'with relative locators' do
    let(:url) do
      form = <<~HTML
        <form>
          <label id="lbl-email" for="email">Email</label> <input id="email" type="email"><br>
          <label id="lbl-password" for="password">Password</label> <input id="password" type="password"><br>
          <button id="cancel" type="button">Cancel</button> <button id="submit" type="button">Submit</button>
        </form>
      HTML
      "data:text/html,#{form}"
    end

    it 'finds element above' do
      ele = driver.find_element(relative: {tag_name: 'input', above: {id: 'password'}})
      expect(ele.attribute('id')).to eq('email')
    end

    it 'finds element below' do
      ele = driver.find_element(relative: {tag_name: 'input', below: {id: 'email'}})
      expect(ele.attribute('id')).to eq('password')
    end

    it 'finds element to the left' do
      ele = driver.find_element(relative: {tag_name: 'button', left: {id: 'submit'}})
      expect(ele.attribute('id')).to eq('cancel')
    end

    it 'finds element to the right' do
      ele = driver.find_element(relative: {tag_name: 'button', right: {id: 'cancel'}})
      expect(ele.attribute('id')).to eq('submit')
    end

    it 'finds near element' do
      ele = driver.find_element(relative: {tag_name: 'input', near: {id: 'lbl-email'}})
      expect(ele.attribute('id')).to eq('email')
    end

    it 'chains relative locators' do
      ele = driver.find_element(relative: {tag_name: 'button', below: {id: 'email'}, right: {id: 'cancel'}})
      expect(ele.attribute('id')).to eq('submit')
    end
  end

With that I get 14 examples, 0 failures and rubocop is happy

One more thing, the gh-codeblock line numbers are off by one right now (#L13 points to the expect line instead of the find_element), and there is still an old #L7 in the table at the bottom of the traditional locators section. With the change above the Ruby refs should be, in the same order on all 4 languages:

L12, L18, L24, L30, L36, L42, L48, L54, L12 (the #L7 one), then the relative ones L72, L77, L82, L87, L92, L97

I hope this helps!😊

@rpallavisharma

rpallavisharma commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

Oh ... I took the java example and converted to ruby

Thank you for the help @aguspe i will fix that and the line number.

Hopefully it will work.

@rpallavisharma

Copy link
Copy Markdown
Member Author

@aguspe can you please help why windows is failing? I'm unable to figure this out.

@rpallavisharma

Copy link
Copy Markdown
Member Author

@aguspe , i think failures are not related to this PR. please can you verify this. thanks.

@aguspe

aguspe commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Hi @rpallavisharma !

You are right, the Windows failures have nothing to do with your changes

The only test that still fails after the retries is spec/actions_api/mouse_spec.rb:93 (Mouse move by offset offset from element). It's an off-by-one coordinate check (expect(x_coord).to be_within(1).of(center_x + 8)) that has been failing on Windows for a few days now.

Your locator specs pass on all platforms, so from my side this is good. I can look into the mouse spec separately so it stops blocking PRs! :)

@rpallavisharma
rpallavisharma requested review from AutomatedTester and diemol and a balanced review from Copilot and removed request for Copilot November 23, 2026 05:07
@rpallavisharma

Copy link
Copy Markdown
Member Author

Thank you @aguspe . @diemol / @AutomatedTester kindly please either of you merge the PR . thank you.

@aguspe aguspe left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rpallavisharma ! almost there :) there is still an old #L7 in the Ruby tab under "Utilizing Locators", it should be #L12 (locators.en.md 321, ja 319, pt-br 322, zh-cn 323). I can't comment on those lines because they are not in the diff

@rpallavisharma
rpallavisharma enabled auto-merge (squash) November 25, 2026 05:29
@rpallavisharma

Copy link
Copy Markdown
Member Author

@aguspe , i think all is good now. please confirm. @diemol /@AutomatedTester, please merge. thanks.

@rpallavisharma

Copy link
Copy Markdown
Member Author

@SeleniumHQ/selenium-tlc please see.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Code File of ruby in locator page should be a standalone working example

2 participants