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

Selemiumbase Driver switches to another tab #2328

Closed
ZoneLover opened this issue Nov 30, 2023 · 4 comments
Closed

Selemiumbase Driver switches to another tab #2328

ZoneLover opened this issue Nov 30, 2023 · 4 comments
Labels
question Someone is looking for answers UC Mode Undetected Chromedriver Mode (--uc)

Comments

@ZoneLover
Copy link

ZoneLover commented Nov 30, 2023

After opening those three tabs, the driver switches from the third tab to the second one or the first one.
It doesn't happen with the selenium driver nor the uc_chromedriver.
I managed to reproduce the bug with the following code:
happened on Python 3.9 & 3.11.6

from seleniumbase import Driver
AMAZON_PRIME_LOGIN = "https://www.amazon.com/ap/signin?openid.pape.max_auth_age=3600&openid.return_to=https%3A%2F%2Fgaming.amazon.com%2Fprime%2Fsignup%2Feg%3Fingress%3Damzn%26ref_%3Dsm_w_ics_m_f_all&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_respawn_desktop_us&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&ssoResponse=eyJ6aXAiOiJERUYiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiQTI1NktXIn0.yf9Wgo4I2tZaftdNDV9dGzDE3WBRtCwlofy9T0xdJFn6Z8J9GkkQ2A.YfhrqNQaRSrDgXpJ.5jj055CVEHpYJa2zcCUKxxPSxxcSeVjvQFpUjEP-_kOek_h1S8Zy6jujXVJSGJtsliAleSPGnrlvysESKkSEXnAWFOvJRcE9JepYQJulvu"
AMAZON_PRIME_GAMING = "https://gaming.amazon.com/prime-gaming-capsule-nov-23/dp/amzn1.pg.item.fe075900-6304-4e90-a13d-d5e04635dca9?ingress=amzn&ref_=SM_LeagueofLegends_S13_D09_CRWN"
AMAZON_NUMBER_SETTING = "https://www.amazon.com/ap/profile/mobilephone?ref_=ax_am_landing_add_mobile&openid.assoc_handle=usflex&referringAppAction=CNEP"
driver = Driver(uc= True)
driver.get(AMAZON_PRIME_LOGIN)
driver.switch_to.new_window('tab')
driver.get(AMAZON_PRIME_GAMING)
driver.switch_to.new_window('tab')
driver.get(AMAZON_NUMBER_SETTING)
input()
driver.quit()

@ZoneLover
Copy link
Author

ZoneLover commented Nov 30, 2023

Update: it happens only with one of those:
driver = Driver(uc= True)
driver = Driver(undetectable=True)
driver = Driver(undetected= True)

@mdmintz mdmintz added question Someone is looking for answers UC Mode Undetected Chromedriver Mode (--uc) labels Nov 30, 2023
@mdmintz
Copy link
Member

mdmintz commented Nov 30, 2023

Even regular undetected-chromedriver didn't let you use the standard tab-switching methods as is:

Tab-switching works differently in UC Mode. (The standard SeleniumBase formats have additional methods for that.)

Here's an example of that:

from seleniumbase import SB

with SB(uc=True) as sb:
    sb.driver.uc_open_with_tab("data:text/html,<h1>Page A</h1>")
    sb.assert_text("Page A")
    sb.open_new_window()
    sb.driver.uc_open_with_tab("data:text/html,<h1>Page B</h1>")
    sb.assert_text("Page B")
    sb.switch_to_window(0)
    sb.assert_text("Page A")
    sb.assert_text_not_visible("Page B")
    sb.switch_to_window(1)
    sb.assert_text("Page B")
    sb.assert_text_not_visible("Page A")

If you need more than one tab open, first call sb.open_new_window(), then call sb.driver.uc_open_with_tab(url). This will maintain window ordering and numbering.

Also note that having more than one tab open at a time will likely lead to Selenium detection, so you're probably better off having only one tab/window open at a time for tests.

@mdmintz mdmintz closed this as completed Nov 30, 2023
@ZoneLover
Copy link
Author

@mdmintz
I executed similar code and it generates the same issue,
I didn't clarify the issue properly.
When u execute the code below, the driver switches from the third tab to the first tab which doesn't exist in the code.
This issue doesn't happen on uc_chromedriver nor selenium driver,
This issue only happens when using Seleniumbase with uc mode.
The code that produces the issue:

from seleniumbase import SB
AMAZON_PRIME_LOGIN = "https://www.amazon.com/ap/signin?openid.pape.max_auth_age=3600&openid.return_to=https%3A%2F%2Fgaming.amazon.com%2Fprime%2Fsignup%2Feg%3Fingress%3Damzn%26ref_%3Dsm_w_ics_m_f_all&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_respawn_desktop_us&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&ssoResponse=eyJ6aXAiOiJERUYiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiQTI1NktXIn0.yf9Wgo4I2tZaftdNDV9dGzDE3WBRtCwlofy9T0xdJFn6Z8J9GkkQ2A.YfhrqNQaRSrDgXpJ.5jj055CVEHpYJa2zcCUKxxPSxxcSeVjvQFpUjEP-_kOek_h1S8Zy6jujXVJSGJtsliAleSPGnrlvysESKkSEXnAWFOvJRcE9JepYQJulvu"
AMAZON_PRIME_GAMING = "https://gaming.amazon.com/prime-gaming-capsule-nov-23/dp/amzn1.pg.item.fe075900-6304-4e90-a13d-d5e04635dca9?ingress=amzn&ref_=SM_LeagueofLegends_S13_D09_CRWN"
AMAZON_NUMBER_SETTING = "https://www.amazon.com/ap/profile/mobilephone?ref_=ax_am_landing_add_mobile&openid.assoc_handle=usflex&referringAppAction=CNEP"
with SB(uc=True) as sb:
sb.driver.uc_open_with_tab(AMAZON_PRIME_LOGIN)
sb.open_new_window()
sb.driver.uc_open_with_tab(AMAZON_PRIME_GAMING)
sb.open_new_window()
sb.driver.uc_open_with_tab(AMAZON_NUMBER_SETTING)
input()

@mdmintz
Copy link
Member

mdmintz commented Nov 30, 2023

Those URLs appear to have redirects in them. It's tricky enough for UC Mode to manage tabs after a disconnect because chromedriver is completely disconnected from Chrome during the disconnect/reconnect process. That can cause tab order to change. Also, UC Mode anti-detection likely won't work when using multiple tabs. Therefore, when using UC Mode, try to run your script using a single tab/window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers UC Mode Undetected Chromedriver Mode (--uc)
Projects
None yet
Development

No branches or pull requests

2 participants