Hi
I am getting error ) expeced on below line. Is it correct for like button
var like_btn = _driver.FindElement(By.XPath("//div[@id='info']//ytd-toggle-button-renderer[1]//a[1]//yt-icon-button[1]//button[1]//yt-icon[1]");
Thanks
Hi
I am getting error ) expeced on below line. Is it correct for like button
var like_btn = _driver.FindElement(By.XPath("//div[@id='info']//ytd-toggle-button-renderer[1]//a[1]//yt-icon-button[1]//button[1]//yt-icon[1]");
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mukesh NailwalPosted Jan 5, 2026, 7:15 AM
You’re getting the ) expected error because the line is missing a closing parenthesis for FindElement(...).
Your current line ends with " but never closes the )
Try this
var like_btn = _driver.FindElement(
By.XPath("//div[@id='info']//ytd-toggle-button-renderer[1]//a[1]//yt-icon-button[1]//button[1]//yt-icon[1]")
);
Thanks
Priya PrajapatiPosted Jan 5, 2026, 5:18 AM
You are missing a closing parenthesis :
Sandhiya PriyaPosted Jan 2, 2026, 11:31 AM
The error
) expectedis simply due to a missing closing parenthesis in your code.Your XPath itself is fine, but the method call is not closed properly.
Your current line
Corrected line
What was wrong
By.XPath(opens a parenthesisYou closed the string
"But you did not close the
By.XPath()callHence the compiler reports
) expectedExtra tip (optional)
Your XPath is very long and fragile. A shorter and safer version (if possible) is better, for example:
Summary
Syntax issue, not XPath logic
Missing
)caused the errorYour XPath is valid after fixing parentheses
After adding the missing
), the code will compile correctly.Lalji DhameliyaPosted Apr 12, 2024, 12:26 PM
The error you're encountering is likely due to the missing closing parenthesis at the end of the line. Here's the corrected line:
Jaimin ShethiyaPosted Apr 11, 2024, 12:44 PM
Hello Ramco,
try the below code
Thanks
Satya KarkiPosted Apr 11, 2024, 9:57 AM
Hi,
Closing parenthesis ) is missing.
Naimish MakwanaPosted Apr 10, 2024, 1:17 PM
The error message you’re seeing typically means that the WebDriver is unable to locate an element on the page using the provided XPath. This could be due to several reasons:
The element doesn’t exist: The element you’re trying to select might not exist on the page at the time WebDriver is trying to select it. This could be because the page hasn’t finished loading, or the element is dynamically loaded.
Incorrect XPath: The XPath you’re using might not be correct. It’s possible that the structure of the page has changed, or there was a mistake in the XPath.
Element not visible: WebDriver can only interact with visible elements. If the element is hidden, WebDriver will not be able to interact with it.
Here are a few things you can try to fix this issue:
Wait for the element: You can use explicit waits or implicit waits to give the page some time to load the element.
Check your XPath: Test your XPath in the browser’s developer tools to make sure it’s correct. You can do this by inspecting the element and using the search function in the Elements tab.
Check if the element is visible: Make sure the element is visible on the page when WebDriver is trying to select it. If the element is hidden, you might need to perform some action to make it visible (like scrolling or clicking on a button).
Here’s an example of how you can add an explicit wait to your code:
This code will wait up to 10 seconds for the element to appear on the page before throwing a
NoSuchElementException. If the element appears within 10 seconds, theFindElementmethod will return it immediately.Thanks
Ramco RamcoPosted Apr 10, 2024, 1:05 PM
Hi naimish
I am getting below error
no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id='info']//ytd-toggle-button-renderer[1]//a[1]//yt-icon-button[1]//button[1]//yt-icon[1]"}
Thanks
Jayraj ChhayaPosted Apr 10, 2024, 12:52 PM
The error you are facing is due to a missing closing parenthesis in your XPath expression.
Naimish MakwanaPosted Apr 10, 2024, 12:52 PM
It seems like you’re missing a closing parenthesis
)at the end of your line of code. Here’s the corrected version:Thanks