Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Cant find element using Xpath #14849

Open
anugrahjayaaaa opened this issue Dec 4, 2024 · 4 comments
Open

[🐛 Bug]: Cant find element using Xpath #14849

anugrahjayaaaa opened this issue Dec 4, 2024 · 4 comments
Labels
I-defect I-issue-template Applied to issues not following the template, or missing information.

Comments

@anugrahjayaaaa
Copy link

anugrahjayaaaa commented Dec 4, 2024

What happened?

hi all

I found an issue when creating a regression test using Selenium. Previously, I made a Selenium script for WordPress 6.2 using the same script I used for WordPress 6.5. Specifically, when creating a page, when I wanted to fill in the title with the help of XPath as a selector, for some reason, Selenium could not find the element for the title, and the script failed to execute.

Has anyone experienced this or does anyone know why this could happen? I have tried changing the XPath, adding sleep time, but it still doesn’t work

Thank you

How can we reproduce the issue?

Install WordPress 6.5.5

Create login script for WordPress

Create content script for WordPress, here an example of the ode

here the object repository
public static string POST_TITLE = "//h1[@contenteditable='true' and @aria-label='Add title']";

here is my code to fill the post title

// filled title
_driver.WaitToDisplay(By.XPath(PostObjects.POST_TITLE)).SendKeys(postTitle);

here the page
%%WORDPRESS-DOMAIN%%/wp-admin/post-new.php?post_type=page

here the element targets HTML
<h1 contenteditable="true" class="wp-block wp-block-post-title block-editor-block-list__block editor-post-title editor-post-title__input rich-text" aria-label="Add title" role="textbox" aria-multiline="true" style="white-space: pre-wrap; min-width: 1px;"><span data-rich-text-placeholder="Add title" style="pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;"></span></h1>

Relevant log output

OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//h1[@contenteditable='true' and @aria-label='Add title']"}
  (Session info: chrome=131.0.6778.86); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.WebDriver.FindElement(By by)
   at SeleniumTest.NUnit.Extensions.DriverExtensions.WaitToDisplay(IWebDriver driver, By by, Int32 timeout, Boolean retry) in D:\Laragon\www\domain.cms.php.internal\CWP2.Regression.Test\Wordpress\SeleniumTest.NUnit\Extensions\DriverExtensions.cs:line 58
   at SeleniumTest.NUnit.Extensions.DriverExtensions.WaitToDisplay(IWebDriver driver, By by) in D:\Laragon\www\domain.cms.php.internal\CWP2.Regression.Test\Wordpress\SeleniumTest.NUnit\Extensions\DriverExtensions.cs:line 27
   at SeleniumTest.NUnit.NF.SeleniumTestSuite._CreateContent(String postTitle, String postBodyContent, String testName) in D:\Laragon\www\domain.cms.php.internal\CWP2.Regression.Test\Wordpress\SeleniumTest.NUnit\SeleniumTestSuite.cs:line 462
   at SeleniumTest.NUnit.NF.SeleniumTestSuite.CreateContent() in D:\Laragon\www\domain.cms.php.internal\CWP2.Regression.Test\Wordpress\SeleniumTest.NUnit\SeleniumTestSuite.cs:line 412

Operating System

Windows and Ubuntu

Selenium version

.net 6

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 131.0.6778.87/win32

Are you using Selenium Grid?

No response

Copy link

github-actions bot commented Dec 4, 2024

@anugrahjayaaaa, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol diemol added I-issue-template Applied to issues not following the template, or missing information. and removed needs-triaging labels Dec 4, 2024
Copy link

github-actions bot commented Dec 4, 2024

Hi, @anugrahjayaaaa.
Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

@anugrahjayaaaa
Copy link
Author

hi, sorry. updated the first comment.
thanks

@pujagani
Copy link
Contributor

pujagani commented Dec 5, 2024

Please provide a reproducible test script/repo with minimum dependencies so that we can reproduce the issue and help narrow down the root cause. It will be nice to have a complete code snippet that we could simple copy-paste and it will help reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-defect I-issue-template Applied to issues not following the template, or missing information.
Projects
None yet
Development

No branches or pull requests

3 participants