1

Please help because this is driving me nuts.

This should be simple - clicking an element. But for the life of me, I can't find a way to do it.

I can locate it with each method I've tried, but I cannot seem to click it. I've tried by class name, by XPath class, by XPath span text, I've tried forcing the click with javascript. Nothing. This blue OK button is seemingly unclickable.

I'm starting to think it could be because of the div shape, which I'll attach in an image. It looks like the div goes to the left of the button as well, so maybe it's just clicking the empty space next to the button that also happens (for whatever reason) to be covered by the div? If so, is there a way to specify what part of a div is clicked?

Here is what I've tried:

browser.find_element_by_class_name('ok')

browser.find_element(By.XPATH, "//div[@class='ok']")

browser.execute_script("arguments[0].click();",
                                  WebDriverWait(browser, 10).until(EC.element_to_be_clickable
                                                                   ((By.Class, "ok"))))

browser.FindElement(By.XPath("//div[@class='ok']/span[@class='OK']"));

HTML code for element in question The OK button I am trying to click the div covering blank space to the left of the button

  • what's the xpath you used? And can you please share the trace – supputuri Jan 14 '20 at 18:54
  • have you tried with xpath “//span[.=‘OK’]”? Please share also what you have tried till now? – Muzzamil Jan 14 '20 at 20:18
  • Does this answer your question? [Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-x-y-other-elem) – Sers Jan 14 '20 at 21:43
  • aplogies, i will edit the question with what I've tried – bboooooyintheuk Jan 15 '20 at 06:18
  • Try : //*[@class='ok']/[contains(text(),'OK')] – Amit Jan 15 '20 at 07:15

1 Answers1

0

You need to target the text of the <span> tag:

xpath = "//div[@class='ok']/span[contains(., 'OK')]";

browser.find_element_by_xpath(xpath);

I get the element not interactable error still?

You need to "wait" for the element to be clickable. Race conditions between the browser and Selenium can cause an element to be in the DOM before you are able to click on it, for instance if you have an animation that fades an object in.

xpath = "//div[@class='ok']/span[contains(., 'OK')]";
wait = WebDriverWait(browser, 10);
okButton = wait.until(EC.element_to_be_clickable(xpath));

okButton.click();
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • @bboooooyintheuk: I updated my answer. You need to use a WebDriverWait object to wait until the element is clickable before clicking it. – Greg Burghardt Jan 16 '20 at 12:06
  • hey, had to tweak code slightly but I'm getting `TypeError: find_element() argument after * must be an iterable, not WebElement`? My code: `xpath = browser.find_element_by_xpath("//div[@class='ok']/span[contains(., 'OK')]"); wait = WebDriverWait(browser, 10); okButton = wait.until(EC.element_to_be_clickable(xpath)); okButton.click();` – bboooooyintheuk Jan 16 '20 at 14:19
  • Thanks. I fixed my question. I don't write much Python. – Greg Burghardt Jan 16 '20 at 14:50