1

I'm having trouble with clicking at an element, which I find using text which is a variable. This is the code of the page:

<div class="recommendedProfileList fl">
<h3>
<ul class="ctrlResearchProfiles">
<li>
<li>
<li>
<li>
<li>
<li>
<span class="profileBtn ctrlSelectDefProfile ctrlClickSubmit" data-value="143" data-form="formChooseProfile" data-profileid="143">Sales manager</span>
<span class="profileTooltip" style="display: none;">
<span class="arrow"/>
<span class="profileTooltipContent">
</span>

and the name of the variable is profile. This is how I've tried to do this, but did not work:

WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()=' + profile + ']")));

second:

driver.findElement(By.xpath("//*[text()=' + profile + ']"));

also:

driver.findElement(By.linkText("" +profile)).click();

Do you know how to click such element?

3
  • Do you try to click on the span element with class "profileBtn" ? Commented Mar 26, 2015 at 9:23
  • Yes, and I want to refer to Sales manager. There are few familiar element on the page and data-value is different for each too but I have no idea how to use that one so I've been trying with the name Commented Mar 26, 2015 at 9:31
  • Did you debug your code to see if the call to driver.findElement(...) returns the right WebElement instance object? This may help you to figure out what's wrong. Does the click has no effect or does the findElement returns the wrong element? Commented Mar 26, 2015 at 9:37

1 Answer 1

2

You are almost there buddy...

wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='" + profile + "']")));

second:

driver.findElement(By.xpath("//*[text()='" + profile + "']"));

The thing that you missed was double quotes to insert ur variable values in xpath.

Sign up to request clarification or add additional context in comments.

1 Comment

your hint worked, the element has been found. it turned out, the element is invisible...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.