The code does work below when the access to the webpage, it automatically hide #OrderDeliveryAddress
div. But I am wondering is this correct way doing it?
Is there a way to check if .selectAddressList
div/class exist first and then check the value?
$(document).ready(function() {
if ($(".selectAddressList").val() == "selectAddressBook") {
$("#OrderDeliveryAddress").hide();
}
});
We can use the in-built python List method, count(), to check if the passed element exists in the List. If the passed element exists in the List, the count() method will show the number of times it occurs in the entire list. If it is a non-zero positive number, it means an element exists in the List.
contains DOM API, you can check for the presence of any element in the page (currently in the DOM) quite easily: document. body. contains(YOUR_ELEMENT_HERE);
Using driver. In order to check if an element is present on a webpage, we make use of driver. findElements() method. As we know that driver. findElements() method returns a list of webElements located by the “By Locator” passed as parameter.
Personally I would use:
if ($(".selectAddressList").length > 0)
This checks if the jQuery object has any items, in other words if anything matched the selector you passed in.
if($(".selectAddressList").length > 0)
At a second glance though, you're using a class selector for this - do you have multiple items using this class on the page? If so, you might run into conflicts there as you're checking the .val()
of it/them. If not, you might consider using element id
as opposed to class
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With