简体   繁体   中英

How can I access an element inside of a Javascript with Selenium?

There is an element inside of a javascript file, hence if it's executed an element (class) will appear on-site. How am I able to find an element inside the javascript file with Selenium?

<body>
#...
    <script src="../public/vendor.bundle.js"></script>
#...
</body>

That's the output of the driver.page_source

I saw that there is an element inside of the.js as I inspected it locally within my Google Chrome browser. Though how am I able to access it with Selenium?

there are three ways to find an element inside.js while in selenium

  1. isDisplayed() The isDisplayed method in Selenium verifies if a certain element is present and displayed. If the element is displayed, then the value returned is true. If not, then the value returned is false.

The code below verifies if an element with the id attribute value next is displayed.

Syntax:

boolean eleSelected= driver.findElement(By.xpath("xpath")).isDisplayed();
  1. isSelected() This method is often used on radio buttons, checkboxes or options in a menu. It is used to determine is an element is selected. If the specified element is selected, the value returned is true. If not, the value returned is false.

The code below verifies if an element with the id attribute value PersistentCookie is displayed.

Syntax:

boolean elePresent = driver.findElement(By.xpath("xpath")).isSelected();
  1. isEnabled() This method verifies if an element is enabled. If the element is enabled, it returns a true value. If not, it returns a false value.

The code below verifies if an element with the id attribute value next is enabled.

Syntax:

boolean eleEnabled= driver.findElement(By.xpath("xpath")).isEnabled();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM