Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: alerts not working properly #15068

Closed
bestchatgptuser opened this issue Jan 13, 2025 · 12 comments
Closed

[🐛 Bug]: alerts not working properly #15068

bestchatgptuser opened this issue Jan 13, 2025 · 12 comments
Labels
I-defect I-issue-template Applied to issues not following the template, or missing information.

Comments

@bestchatgptuser
Copy link

What happened?

tried triggering an alert, then dismissing it, but Selenium never detects the alert. it's just that.
image

How can we reproduce the issue?

vSPDescendants.ElementAt(0).Click(); //trigger alert
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.AlertIsPresent()); //errors here. if i remove this, it will error on the next line
IAlert alert = driver.SwitchTo().Alert(); //errors here if the wait stuff is removed
alert.Dismiss(); //this code is copied straight from selenium docs, by the way

Relevant log output

Unhandled exception. OpenQA.Selenium.WebDriverTimeoutException: Timed out after 10 seconds
   at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition, CancellationToken token)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at thingyy.Program.Main(String[] args) in C:\Users\alexa\source\repos\thingyy\thingyy\Program.cs:line 36
Attempting to use a delegate that only supports static-sized tensors with a graph that has dynamic-sized tensors (tensor#58 is a dynamic-sized tensor).

Operating System

windows 11

Selenium version

C# 4.27.0

What are the browser(s) and version(s) where you see this issue?

chrome 131.0.6778.265

What are the browser driver(s) and version(s) where you see this issue?

i honestly have no clue atp

Are you using Selenium Grid?

No response

Copy link

@bestchatgptuser, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol diemol added I-issue-template Applied to issues not following the template, or missing information. and removed needs-triaging labels Jan 13, 2025
Copy link

Hi, @bestchatgptuser.
Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

@bestchatgptuser
Copy link
Author

it just does not get simpler than this. a popup appears, and Selenium doesn't detect it

@diemol
Copy link
Member

diemol commented Jan 13, 2025

Selenium can interact web app pop-ups, not OS level pop-ups. Check that, please.

Otherwise, we need a way to reproduce the issue.

@shbenzer
Copy link
Contributor

Selenium can interact web app pop-ups, not OS level pop-ups. Check that, please.

If it is an OS level pop-up, I've used pyautogui for them successfully before

@bestchatgptuser
Copy link
Author

it's a web app pop-up

@diemol
Copy link
Member

diemol commented Jan 13, 2025

@bestchatgptuser looking forward to see your code script so we can reproduce the issue!

@chukarski
Copy link

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'

# @param headless [Boolean] browser: :chrome or :firefox
# @param opts [Array] additional browser command line options
def browser_opts(headless: false, opts: [])
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument('--ignore-certificate-errors')
  options.add_argument('--no-sandbox')
  options.add_argument('--disable-search-engine-choice-screen')
  options.add_argument('--headless') if headless
  options.accept_insecure_certs = true
  options.add_option(:web_socket_url, true)
  options.unhandled_prompt_behavior = :ignore
  opts&.each { |opt| options.add_argument(opt) }
  options
end

Capybara.register_driver(:chrome) do |app|
  driver = Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: browser_opts(headless: true)
  )
  driver
end

Capybara.threadsafe = true
Capybara.default_driver = :chrome
Capybara.javascript_driver = :chrome

@page = Capybara::Session.new(:chrome) do |config|
  config.run_server = false
  config.default_max_wait_time = 5
end
# below triggers Unsaved changes dialog
@page.visit('https://regex101.com/')
@page.all('div.cm-content.cm-lineWrapping').each do |element|
  element.send_keys 'Data'
end
sleep 5
puts 'Waiting for Alert'
begin
  @page.accept_alert(/.*/, wait: 5) { @page.visit('https://google.com/') }
rescue Capybara::ModalNotFound
  puts 'unable to find modal dialog in 5 seconds'
end
alert = @page.page.driver.browser.switch_to.alert.text
puts "alert -> #{alert.text}"
exit 0

No alert is seen

Waiting for Alert
/usr/local/bundle/gems/selenium-webdriver-4.27.0/lib/selenium/webdriver/common/wait.rb:73:in `until': timed out after 30 seconds (Selenium::WebDriver::Error::TimeoutError)
	from /usr/local/bundle/gems/selenium-webdriver-4.27.0/lib/selenium/webdriver/common/websocket_connection.rb:75:in `send_cmd'
	from /usr/local/bundle/gems/selenium-webdriver-4.27.0/lib/selenium/webdriver/bidi.rb:56:in `send_cmd'
	from /usr/local/bundle/gems/selenium-webdriver-4.27.0/lib/selenium/webdriver/bidi/browsing_context.rb:49:in `navigate'
	from /usr/local/bundle/gems/selenium-webdriver-4.27.0/lib/selenium/webdriver/remote/bidi_bridge.rb:33:in `get'
	from /usr/local/bundle/gems/selenium-webdriver-4.27.0/lib/selenium/webdriver/common/navigation.rb:32:in `to'
	from /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:95:in `visit'
	from /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/session.rb:281:in `visit'
	from regex101.rb:48:in `block in <main>'
	from /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:265:in `accept_modal'
	from /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/session.rb:850:in `accept_modal'
	from /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/session.rb:660:in `accept_alert'
	from regex101.rb:48:in `<main>'

@diemol
Copy link
Member

diemol commented Jan 17, 2025

Image

This prompt you get when navigating to Google is not an alert. You can inspect it and click on the button you prefer.

I will close this issue because we never got a script to reproduce the problem.

@diemol diemol closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 2025
@chukarski
Copy link

I do not see the google page, I see Unsaved Changes alert, but selenium does not see them

Image

with options

  options.add_option(:web_socket_url, true)
  options.unhandled_prompt_behavior = :ignore

All simple dialogs encountered should be left to the user to handle.

@diemol
Copy link
Member

diemol commented Jan 17, 2025

That is not a web pop-up or an alert. It is an OS prompt created by the browser itself.

@chukarski
Copy link

But with gem install selenium-webdriver -v 4.26.0, it works as expected. Last lines of script are modified to

sleep 5
puts 'Waiting for Alert'
@page.visit('https://google.com/')
alert = @page.driver.browser.switch_to.alert
puts "alert -> #{alert}"
alert.accept
puts "URL #{@page.current_url}"
exit 0

And it gives

Waiting for Alert
alert -> #<Selenium::WebDriver::Alert:0x0000000128bd0870>
URL https://www.google.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-defect I-issue-template Applied to issues not following the template, or missing information.
Projects
None yet
Development

No branches or pull requests

4 participants