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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 10, 2024, 8:52 AM EDT
It seems like you’re missing a closing parenthesis
)at the end of your line of code. Here’s the corrected version: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
Jayraj ChhayaRank #304 · 8.2K reputationPosted Apr 10, 2024, 8:52 AM EDT
The error you are facing is due to a missing closing parenthesis in your XPath expression.
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]"));Ramco RamcoRank #462 · 5.4K reputationPosted Apr 10, 2024, 9:05 AM EDT
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
Satya KarkiRank #78 · 24.6K reputationPosted Apr 11, 2024, 5:57 AM EDT
Hi,
Closing parenthesis ) is missing.
Lalji DhameliyaRank #3,336 · 431 reputationPosted Apr 12, 2024, 8:26 AM EDT
The error you're encountering is likely due to the missing closing parenthesis at the end of the line. Here's the corrected line:
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]"));Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 10, 2024, 9:17 AM EDT
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:
WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10)); var like_btn = wait.Until(drv => drv.FindElement(By.XPath("//div[@id='info']//ytd-toggle-button-renderer[1]//a[1]//yt-icon-button[1]//button[1]//yt-icon[1]")));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
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Apr 11, 2024, 8:44 AM EDT
Hello Ramco,
try the below code
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
Sandhiya PriyaRank #26 · 43.2K reputationPosted Jan 2, 2026, 6:31 AM EST
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
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]");Corrected line
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]") );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:
By.XPath("//div[@id='info']//ytd-toggle-button-renderer//button")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.Priya PrajapatiRank #1,224 · 1.5K reputationPosted Jan 5, 2026, 12:18 AM EST
You are missing a closing parenthesis :
Mukesh NailwalRank #793 · 2.9K reputationPosted Jan 5, 2026, 2:15 AM EST
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