0

I wanted to find out following "new request" button from the html page(mentioned below to button tag)

<button class="as-main-button definitely-not-a-aff-button" onclick="window.location.href='/FireFlow/SelfService/ChooseTemplate.html?Queue=1';">+ &nbsp;New Request</button>

Following is the code I tried but after so many tries still not able to find out that the desired button, still not sure why that button is not visible to the code, following is the code:

try:
    button_class_name = "button.as-main-button.definitely-not-a-aff-button"
    element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, button_class_name)))
    logging.info("New Request element is visible")

    time.sleep(5)
except Exception as e:
    logging.error(f"Failed to create new request : {e}")

And I got following error all the time:

2023-08-10 01:34:45,850 - ERROR - Failed to create new request : Message: 
Stacktrace:
Backtrace:
    GetHandleVerifier [0x003EA813+48355]
    (No symbol) [0x0037C4B1]
    (No symbol) [0x00285358]
    (No symbol) [0x002B09A5]
    (No symbol) [0x002B0B3B]
    (No symbol) [0x002DE232]
    (No symbol) [0x002CA784]
    (No symbol) [0x002DC922]
    (No symbol) [0x002CA536]
    (No symbol) [0x002A82DC]
    (No symbol) [0x002A93DD]
    GetHandleVerifier [0x0064AABD+2539405]
    GetHandleVerifier [0x0068A78F+2800735]
    GetHandleVerifier [0x0068456C+2775612]
    GetHandleVerifier [0x004751E0+616112]
    (No symbol) [0x00385F8C]
    (No symbol) [0x00382328]
    (No symbol) [0x0038240B]
    (No symbol) [0x00374FF7]
    BaseThreadInitThunk [0x75AA7D59+25]
    RtlInitializeExceptionChain [0x7761B79B+107]
    RtlClearBits [0x7761B71F+191]

This is my web page I look into (not the entire page):

https://gist.github.com/indrajeetgour/a54b8f2f89aaafe6160cb8bfe189ff66

Do let me know if something more required for this problem to solve. Just to mentioned I am new to the selenium. Please help me out.

Update1: I forgot to mentioned that, I got into this page from another page, do you guys see should I switch the driver first before searching for any element in the new page(as mentioned above)

Indrajeet Gour
  • 4,020
  • 5
  • 43
  • 70

2 Answers2

0

Given the html:

<button class="as-main-button definitely-not-a-aff-button" onclick="window.location.href='/FireFlow/SelfService/ChooseTemplate.html?Queue=1';">+ &nbsp;New Request</button>

To identify the element with text + New Request instead of presence_of_element_located() you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.as-main-button.definitely-not-a-aff-button[onclick^='window.location.href']")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//button['as-main-button definitely-not-a-aff-button' and contains(., 'New Request')]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for responding, I added some more context to the question as update1. As still I could not find the right element as suggested, do you think should I change anything to it. – Indrajeet Gour Aug 10 '23 at 16:18
0

This css selector is working for me: "#actionsPanel button"

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • Thanks for responding, I added some more context to the question as update1. As still I could not find the right element as you suggest, do you think should I change anything to the code. – Indrajeet Gour Aug 10 '23 at 16:18