Question: I need to count the words occurring in an observation. Some observations have only one word, but others have more than one and are separated by "/".

Here is a data set for a reproducible example.

```
data.1 <-read.csv(text = "
obs, a
2, date
3, Ari
4, MO
5, date/Ari
6, date/MO
7, Ari/MO
8, date/Ari/MO
")

```

This is the solution I came up with. But this solution is not counting correctly those observations with only one word.

```
data.2 <-  data.1 %>% 
              mutate(n.words = lengths(gregexpr("/", a)) + 1)

```

This is the output

[![enter image description here](https://i.stack.imgur.com/7Sj8o.png)](https://i.stack.imgur.com/7Sj8o.png)

Any help will be really appreciated.

Thanks.

Answer: 
The desired element is a [Angular](https://angular.io/) element so to click on the element using [Selenium](https://stackoverflow.com/questions/54459701/what-is-selenium-and-what-is-webdriver/54482491#54482491) you have to induce [WebDriverWait](https://stackoverflow.com/questions/49775502/webdriverwait-not-working-as-expected/49775808#49775808) for the `element_to_be_clickable()` and you can use either of the following [Locator Strategies](https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890):

* Using `CSS_SELECTOR`:

```
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-gradient-primary.btn-icon-text[routerlink='/certificate-request/create'][routerlinkactive='active']>i.icon-plus.btn-icon-prepend"))).click()

```
* Using `XPATH`:

```
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@routerlink='/certificate-request/create' and @routerlinkactive='active']/i[@class='icon-plus btn-icon-prepend']"))).click()

```
* **Note** : You have to add the following imports :

```
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

```
Do you have the option to put an id on your button and do it like this?

```
driver.find_element_by_id(<id_of_button>)

```

EDIT:

How about this?

```
driver.find_element_by_xpath('//button[@class="icon-plus btn-icon-prepend"][.="New request"]').click()

```