0

I have a python script where I need to click a button. My function is as follows:

def inviteuser():
    invitebutton.click()
    time.sleep(2.5)
    addressbox = driver.find_element_by_xpath('/html/body/div[9]/div/div/div[2]/div/div[1]/div/div/div/div/div[3]/div/div/div[1]')
    time.sleep(2.5)
    addressbox.send_keys(email)
    time.sleep(2.5)
    sendbutton = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[3]/div[2]')
    sendbutton.click()

When running the script at the button clicking part, I get this message: selenium.common.exceptions.ElementClickInterceptedException: Message: Element <div class="c-sk-modal_footer_actions"> is not clickable at point (834,677) because another element <div class="ReactModal__Overlay ReactModal__Overlay--after-open c-popover c-popover--z_above_fs c-popover--fade"> obscures it

I tried searching for that div, but the search in the browser could not find it.

I also tried driver.find_element_by_css_selector('.c-button .c-button--primary .c-button--medium').click()

HTML code of the items

<div class="c-sk-modal_footer_actions">
<button class="c-button c-button--primary c-button--medium c-button--disabled" data-qa="invite-to-workspace-modal-invite-form-send-button" type="button" aria-disabled="true">
"Send"
::after
</button>
</div>

If it helps at all, this is for the invite people box in slack admin portal

EDIT: So I basically figured out the issue but can't figure out how to fix the issue... So just using the variable sys.argv[1] puts in the email address, but I need to either press space bar , comma, or enter key after. I can get it to work if I specify what the variable email is (email = "test@test.com" then confirm = " ") and adding a second line addressbox.send_keys(confirm) but if I make the variable what I need it to be so it's called from powershell (sys.argv[1]) It doesn't work. It's like it removes what I entered and only puts what's in the variable "confirm"

TL_Arwen
  • 21
  • 1
  • 6
  • 1
    @Firelord Asking for the URL is equavalent to wastage of time and a huge _**No**_ as per SO standards. Instead ask the OP to update the question with text based HTML so prospective answererss can test their answers before puslishing them. – undetected Selenium Jul 06 '22 at 21:18

3 Answers3

1

Try the execute script method which can have a better chance when getting that error. Also you could use implicitly wait instead of time waits to be more effecient.

driver.implicitly_wait(5)

addressbox = driver.find_element_by_xpath('/html/body/div[9]/div/div/div[2]/div/div[1]/div/div/div/div/div[3]/div/div/div[1]')

driver.execute_script("arguments[0].click();", addressbox)
data_sc
  • 459
  • 1
  • 6
  • So the code you put in there was for the address bx, not the send button, so I changed it accordingly, but still doesn't work. Difference is that now, I don't get an error. The button just doesn't click. – TL_Arwen Jul 06 '22 at 17:50
0

Generally <div> elements aren't clickable. Presumably you need to crosscheck if the following element is your desired element:

<div class="c-sk-modal_footer_actions">

Where as, the element from your second attempt:

<div class="c-button c-button--primary c-button--medium...">

looks as a perfect clickable candidate.


Solution

The desired element is a React element, so to click() on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".c-button.c-button--primary.c-button--medium"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@class='c-button c-button--primary c-button--medium']"))).click()
    
  • 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
0

It turns out that this particular site doesn't allow for doing this so you have to pay to access their api.

TL_Arwen
  • 21
  • 1
  • 6
  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - [From Review](/review/late-answers/34646897) – tread Jul 11 '23 at 17:23