Reputation: 67
When use the condition in Console it says the condition is true but when I run the script, I'm getting the unable to find the element.
Below is the HTML:
<div class="ipc-button__text">Sign In</div>
And the XPath I'm trying to use:
(//div[@class='ipc-button__text']) and (//div[contains(text(),'Sign')])
Upvotes: 1
Views: 119
Reputation: 261
There might be the reason that XPath of the element is not loaded when we trying to perform action instead of doing simple use explicit wait condition before performing any action try to use the below approach.
// xpath = //*[contains(text(),"Sign In")]
WebDriverWait wait = new WebDriverWait(driver, timeInSeconds);
WebElement element
= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
// Perform any action
element.click();
Upvotes: 0
Reputation: 978
Please use following xpath ---- //*[contains(text(),"Sign In")]
Upvotes: 0
Reputation: 29022
Try combining the expressions.
//div[@class='ipc-button__text' and contains(text(),'Sign')]
This should fix the issue.
Otherwise each //div
expression would be evaluated separately and result in the whole expression being true
(because both //div[@class='ipc-button__text']
and //div[contains(text(),'Sign')]
are true
somewhere in the document), but without a specific div
element selected matching both sub-expressions.
Upvotes: 2