简体   繁体   中英

How does this HTML element make a click without any link tag and how to click it via Selenium?

I've run into this scenario on many ocassions when I'm trying to click on a particular element via Selenium.

It's a div element and nothing happens when we click on it via automation. The strange thing is that this element tree doesn't contain any link tags.

Here's an example URL: https://www.quora.com/What-are-some-of-the-best-ways-to-learn-programming Try clicking on the "request" button to open this dialog.

照片描绘了我们想要点击的内容

I'm trying to avoid using mouse hover and instead want to click via javascript execution. I'm currently using the following code:

element = driver.find_element_by_xpath("(//div[@class='q-box qu-display--inline-block']/div/div/span/span)[1]")
browser.execute_script("arguments[0].click();", element)

But this click doesn't work.

  1. How does this element make a click without an a-tag in normal user interaction?

  2. If there exists no a-tag then is there any way to make this click via a js call?

When you click on the plus sign, you will see a message displayed on top and plus sign changes to Check mark.

See if this works

driver.find_element_by_xpath(".//span[@name='CirclePlus'][1]").click()

wait = WebDriverWait(driver, 30)
element = wait.until(EC.presence_of_element_located((By.XPATH, './/span[@name='CircleCheckmark'][1]')))
if element.is_displayed():
    print("Invitation sent")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM