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

CSS Selector triggering an exception while inside a Try block #1095

Open
elnath78 opened this issue Apr 5, 2024 · 0 comments
Open

CSS Selector triggering an exception while inside a Try block #1095

elnath78 opened this issue Apr 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@elnath78
Copy link

elnath78 commented Apr 5, 2024

Bug description

Fatal error: Uncaught Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"meta[property='og:price:amount']"} (Session info: chrome=122.0.6261.69)

How could the issue be reproduced

//This is the minimum code to reproduce the erro, it is inside a Try yet it raise an exception and halts the page:

            try {
                // Find the meta tag with the specified OG property
                $metaTag = $driver->findElement(WebDriverBy::cssSelector("meta[property='og:price:amount']"));

                // Get the content attribute of the meta tag
                $price = $metaTag->getAttribute('content');   

                // terminate the session and close the browser
                $driver->quit();              

                return true;

                // Output the value
                //echo "OG Property '{$ogProperty}' Value: {$ogContent}";

            } catch (NoSuchElementException $e) {
                // Handle the case when the element is not present
                //echo "Element not found. Error: " . $e->getMessage();

                return false;
            }  


### Expected behavior

_No response_

### Php-webdriver version

1.15.1

### PHP version

8.2.0

### How do you start the browser driver or Selenium server

Selenium Docker

### Selenium server / Selenium Docker image version

4.18.1-20240224

### Browser driver (chromedriver/geckodriver...) version

where should I run this?

### Browser name and version

where should I run this?

### Operating system

Ubuntu

### Additional context

The page I'm looking up indeed has this meta set, and I also await for the `<body` tag to load with:
    $wait->until(
        WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::tagName('body'))
    );
@elnath78 elnath78 added the bug Something isn't working label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant