title: Text Exception Click (Ruby/Selenium Webdriver)
body: <p>I'm trying to use each do to find texts now. When the object <code>&lt;td align="left"&gt;GOLD&lt;/td&gt;</code> don't show, Ruby will try to click on <code>&lt;td align="left"&gt;STANDARD&lt;/td&gt;</code> and he continue to find one after another until he succeed to find and click . On my last question, Rajagopalan helped me with this code:</p>
  
  <pre><code>["04", "08", "10", "12"].each do |num|
    begin
      browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl#{num}_btnCancelarOn").click
      el3 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl04_GECBtnExpandColumn")
      browser.action.double_click(el3).perform
      break
    rescue
    end
  end
  </code></pre>
  
  <p>So I tried to put text instead of numbers (this is really possible?):</p>
  
  <pre><code>["GOLD", "STANDARD", "ELO", "DIGITAL"].each do |var|
          begin
            browser.find_element(:xpath =&gt; '//td[.="{var}"]')
            el3 = browser.find_element(:xpath =&gt; '//td[.="{var}"]')
            browser.action.double_click(el3).perform
          break
        rescue Selenium::WebDriver::Error::NoSuchElementError
       end
      end
  </code></pre>
  
  <p>And got a error:</p>
  
  <pre><code>C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': no such element: Unable to locate element: {"method":"id","selector":"ctl00_ContentPlaceHolder1_ucInfoCliente_lblCpf"} (Selenium::WebDriver::Error::NoSuchElementError)
    (Session info: chrome=71.0.3578.98)
    (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 6.1.7601 SP1 x86_64)
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/http/common.rb:84:in `new'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/http/common.rb:84:in `create_response'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/http/common.rb:62:in `call'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/bridge.rb:166:in `execute'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/oss/bridge.rb:584:in `execute'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/oss/bridge.rb:552:in `find_element_by'
      from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/search_context.rb:60:in `find_element'
      from C:/test/normaliza conta.rb:58:in `&lt;main&gt;'
  [Finished in 47.5s with exit code 1]
  [shell_cmd: ruby "C:\test\normaliza conta.rb"]
  [dir: C:\test]
  [path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Ruby25-x64\bin]
  </code></pre>
  
  <p>I tried to make more exceptions too, but got error in these code too</p>
  
  <pre><code>begin 
      browser.find_element(:xpath =&gt; '//td[.="DIGITAL"]').click
      el = browser.find_element(:xpath =&gt; '//td[.="STANDARD"]')
      browser.action.double_click(el).perform     
  rescue Selenium::WebDriver::Error::NoSuchElementError
      browser.find_element(:xpath =&gt; '//td[.="ELO"]').click
      el20 = browser.find_element(:xpath =&gt; '//td[.="ELO"]')
      browser.action.double_click(el20).perform   
  rescue Selenium::WebDriver::Error::NoSuchElementError
      browser.find_element(:xpath =&gt; '//td[.="STANDARD"]').click
      el21 = browser.find_element(:xpath =&gt; '//td[.="STANDARD"]')
      browser.action.double_click(el21).perform       
  rescue Selenium::WebDriver::Error::NoSuchElementError
      browser.find_element(:xpath =&gt; '//td[.="GOLD"]').click
      el22 = browser.find_element(:xpath =&gt; '//td[.="GOLD"]')
      browser.action.double_click(el22).perform
  end
  </code></pre>
  
  <p>In this case, he stops on second element ("ELO") and don't reach the third ("STANDARD") and forth ("GOLD"). (Trying to pass through ELO and DIGITAL to reach STANDARD, which is present in my test.)</p>
  
  <pre><code>*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows
  C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': no such element: Unable to locate element: {"method":"xpath","selector":"//td[.="ELO"]"} (Selenium::WebDriver::Error::NoSuchElementError)
  </code></pre>
  
  <p>But got this error too. Any hints about what I can do?</p>