0

I am programming a python scraper with help of Selenium. The first few steps are:

goes on booking.com, insert a city name, selects the first date and then tries to open the check-out calendar.

Here is where my problem occurs. I am not able to click the check-out calendar button (The important are of the website).

I tried to click every element regarding to the to check-out calendar (The elements of check-out calendar) with element.click(). I also tried the method

element = self.browser.find_element_by_xpath('(//div[contains(@class,"checkout-field")]//button[@aria-label="Open calendar"])[1]') self.browser.execute_script("arguments[0].click();", element)

It either does nothing (in case of execute.script() and click() on div elements) or it throws following exception when directly clicking the button:

Element <button class="sb-date-field__icon sb-date-field__icon-btn bk-svg-wrapper"
type="button"> is not clickable at point (367.5,316.29998779296875) 
because another element <div class="sb-date-field__display"> obscures it

Here is a short code to test it:

browser = webdriver.Firefox()
browser.get("https://www.booking.com/")
wait = WebDriverWait(browser, 5)
element = wait.until(EC.presence_of_element_located((
    By.XPATH, '(//div[contains(@class,"checkout-field")]//button[@aria-label="Open calendar"])[1]')))
element = wait.until(EC.element_to_be_clickable((
    By.XPATH, '(//div[contains(@class,"checkout-field")]//button[@aria-label="Open calendar"])[1]')))
element.click()

I have a temporarily solution for my problem but I am not satisfied with it.

element = browser.find_element_by_xpath('(//div[contains(@class,"checkout-field")]//button[@aria-label="Open calendar"])[1]')
hov = ActionChains(browser).move_to_element(element)
hov.click().perform()

This will open the calendar by hovering over the object and clicking it. This strangely opens the calendar. The methods mentioned above still don't work.

Marcelo00
  • 1
  • 1
  • Possible duplicate of [Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click:](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el/44916498#44916498) – undetected Selenium Dec 29 '17 at 12:32
  • @DebanjanB I already checked the post but it is not my problem. I tried every solution suggested. In addition to this, I get a slightly different exception. – Marcelo00 Dec 29 '17 at 13:16

3 Answers3

1

Define clicka as an xpath. Now use executescript to click the element.

driver.execute_script("arguments[0].click();", clicka)
0

I'm not 100% sure that I got everything you posted, because the layout is a bit messy.

However, I tried to test the issue with both Selenium Java and Firefox Scratchpad (a Web Developer tool that allows to run JavaScript scripts) and it worked perfectly - the button was clickable on both of them.

If you're interested in further testing using this tool, this is the code I've used:

In JavaScript:

function getElementByXpath(path) {
   return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

var myElement = getElementByXpath('(//div[contains(@class,"checkout-field")]//button[@aria-label="Open calendar"])[1]')
myElement.click()

and in Java:

FirefoxDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 10);
driver.navigate().to("https://www.booking.com");
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//div[contains(@class,'checkout-field')]//button[@aria-label='Open calendar'])[1]")));
driver.findElement(By.xpath("(//div[contains(@class,'checkout-field')]//button[@aria-label='Open calendar'])[1]")).click();

System.out.println("success");
GalAbra
  • 5,048
  • 4
  • 23
  • 42
  • It was a bit late yesterday and it is my first post. I will improve the layout of my question in the future and thank you for your advice. I will again test it. – Marcelo00 Dec 29 '17 at 11:02
  • I have tested it but the same error message occurred. Clicking the calendar with Firefox Scratchpad worked perfectly fine but not with Selenium + Python. – Marcelo00 Dec 29 '17 at 11:24
0

if your are having the control check out button on all the web site managing with explicit wait required lots of codding you can use implicit wait below is in the java.

    System.setProperty("webdriver.chrome.driver",
   "G:\\TopsAssignment\\SampleJavaExample\\lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
prat22
  • 378
  • 1
  • 3
  • 18
  • The implicitlyWait method doesn't help and I have read that using explicit wait is better than using implicit waits. – Marcelo00 Dec 29 '17 at 11:31
  • fluent wait is better than explicit wait but need to understand the purpose also – prat22 Dec 30 '17 at 03:59