Я пытался сделать клик, но только если элемент кликабелен, но у меня возникла проблема, потому что элемент кликабелен случайно. Первая кнопка может быть доступна на первой, второй, третьей (он был кликабелен в третьей строке, как показано на image ), а четвертая и пятая строки могут появляться иногда, поэтому мне нужно, чтобы Ruby попытался нажать на Cart_ctl00_ctl06_Detail10_ctl04_btnCancelOn
, если не удается нажать кнопку перехода на Cart_ctl00_ctl06_Detail10_ctl08_btnCancelOn
, и это продолжается до последней строки
...
sleep 5
wait = Selenium::WebDriver::Wait.new(:timeout => 40)
wait.until do
browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl04_btnCancelarOn").click
el3 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl04_GECBtnExpandColumn")
browser.action.double_click(el3).perform
rescue Selenium::WebDriver::Error::NoSuchElementError
browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl08_btnCancelarOn").click
el5 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl04_GECBtnExpandColumn")
browser.action.double_click(el5).perform
rescue Selenium::WebDriver::Error::NoSuchElementError
browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl10_btnCancelarOn").click
el6 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl04_GECBtnExpandColumn")
browser.action.double_click(el6).perform
rescue Selenium::WebDriver::Error::NoSuchElementError
browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl12_btnCancelarOn").click
el7 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl04_GECBtnExpandColumn")
browser.action.double_click(el7).perform
rescue Selenium::WebDriver::Error::NoSuchElementError
end
browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl06_btnCancelarOn").click
el8 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_GECBtnExpandColumn")
browser.action.double_click(el8).perform
...
HTML из третьей строки:
<input type="image" name="ctl00$ContentPlaceHolder1$ucCancBloqRem$gridListCartoes$ctl00$ctl06$Detail10$ctl08$btnCancelarOn" id="ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl08_btnCancelarOn" title="Cancelar Cartão" src="../../../App_Themes/Con/Images/CancelarOn.png" style="border-width:0px;">
Error
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': unknown error: Element <input type="image" name="ctl00$ContentPlaceHolder1$ucCancBloqRem$gridListCartoes$ctl00$ctl06$Detail10$ctl08$btnCancelarOn" id="ctl00_ContentPlaceHolder1_ucCancBloqRem_gridListCartoes_ctl00_ctl06_Detail10_ctl08_btnCancelarOn" title="Cancelar Cartão" src="../../../App_Themes/Con/Images/CancelarOn.png" style="border-width:0px;"> is not clickable at point (563, 150). Other element would receive the click: <div class="raDiv">...</div> (Selenium::WebDriver::Error::UnknownError)
(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:326:in `click_element'
from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/element.rb:72:in `click'
from C:/test/driver_teste3.rb:48:in `rescue in block in <main>'
from C:/test/driver_teste3.rb:44:in `block in <main>'
from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/wait.rb:54:in `until'
from C:/test/driver_teste3.rb:43:in `<main>'
[Finished in 55.0s with exit code 1]
[shell_cmd: ruby "C:\test\driver_teste3.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]