0

Description: I work on scraping the stocks on site www.di.se. The site content is blocked by a banner. I have always clicked the cross by the code:

driver.findElement(By.id("ElementName")).click();

Exact name on the element is now: "svg.icon.icon--feather-close.icon-feather".

But recenly the have done something so this code to click away banner by clicking the cross is not working.

Question How do I click the cross on the banner to make it disappear?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

The Close icon seems to be had been removed from the current deployment.

As an alternative you can click() on Godkänn alla element within the banner element inducing WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button#didomi-notice-agree-button"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='didomi-notice-agree-button']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I really wonder if we have the same view? I can see a cross in the top right corner of the banner but not the button "godkänn och stäng". The banner is internal ad about a digital subscription of their paper. – torbjörn södheim Jan 20 '22 at 21:48
  • @torbjörnsödheim Not a native German, the text is _Godkänn alla_ with _id_ as `didomi-notice-agree-button` which I've incorporated within the answer. – undetected Selenium Jan 20 '22 at 21:55
  • I tested to open DI link with Edge browser and I get a different ad than with Chrome I use with Selenium. Probably you see a different ad because we use different browsers! – torbjörn södheim Jan 20 '22 at 22:13
  • Finally I resolved the issue but it was a strange fault! The banner did not popup when program ran headless so I just comment the click and then all was ok! The strange thing is when not ran headless a banner like the one you describe (using Chrome browser with Selenium). When webbrowsing I use Chrome as browser but the banner wasn't like the other I described before with a cross. I don't understand why site differs and why headless and not headless are different!? – torbjörn södheim Jan 22 '22 at 18:47