0

In the website, https://www.napaonline.com/, how do I click on the button named "Find an Autocare Center"? It is located at the bottom right. I've tried

web_driver$findElements(
  using = "xpath", 
  value = 

With different paths in the value argument without success.


driver <- rsDriver( 
  browser = c("chrome"), 
  chromever = "114.0.5735.90", 
  verbose = T, 
  extraCapabilities = list("chromeOptions" = list(args = list("--headless"))) 
) 
web_driver <- driver[["client"]] 
djmonki
  • 3,020
  • 7
  • 18
Nip
  • 387
  • 4
  • 11

1 Answers1

0

Considering the HTML:

<button class="nol-button mobile-fullWidth marg-xsv-vrt-md yellow change-my-store-link" data-facilitytype="autocare">Find an Autocare Center</button>

To click on the clickable element you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    button[data-facilitytype='autocare']
    
  • Using XPATH:

    //button[@data-facilitytype='autocare']
    

Solution

Your effective code block will be:

web_driver$findElements(
  using = "xpath", 
  value = "//button[@data-facilitytype='autocare']"

Update

To click on the element Find an Autocare Center you can use either of the following locator strategies:

  • Using css selector:

    FindanAutocareCenter <- web_driver$findElement(using = "css selector", "button[data-facilitytype='autocare']")$clickElement()
    
  • Using xpath and data-facilitytype attribute:

    FindanAutocareCenter <- web_driver$findElement(using = "xpath", "//button[@data-facilitytype='autocare']")$clickElement()
    
  • Using xpath, data-facilitytype attribute and the text Find an Autocare Center:

    FindanAutocareCenter <- web_driver$findElement(using = "xpath", "//button[@data-facilitytype='autocare' and text()='Find an Autocare Center']")$clickElement()
    

Reference

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I get `Error: attempt to apply non-function` when using your suggestion. I'll update what is `web_driver` is, since I think a solution might depend on it. – Nip Jun 28 '23 at 13:47
  • @Nip Checkout the answer update and let me know the status. – undetected Selenium Jul 01 '23 at 00:05
  • No luck. ` Error: Summary: NoSuchElement Detail: An element could not be located on the page using the given search parameters. class: org.openqa.selenium.NoSuchElementException Further Details: run errorDetails method`. Same error for the all above alternatives. – Nip Jul 03 '23 at 02:44
  • @Nip Add some wait before attempting to click on the element. Using Python similar approach worked for me. – undetected Selenium Jul 03 '23 at 08:02
  • It think it doesn't even find the element. `Selenium message:no such element: Unable to locate element: {"method":"css selector","selector":"button[data-facilitytype='autocare']"}`. The same happends with other paths. – Nip Jul 03 '23 at 14:37
  • `Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//button[@data-facilitytype='autocare' and text()='Find an Autocare Center']"}`. – Nip Jul 03 '23 at 14:38
  • I just realized that I need to "verify you are human". – Nip Jul 03 '23 at 16:01