-1

I have been told that I can check the "z-index" attribute of web elements to check the depth of them. I first used one of the following two statements to locate the element successfully.

e = WebDriverWait(tA.driver,1).until(EC.visibility_of_element_located((By.XPATH, xPath)))
e = WebDriverWait(tA.driver, 1).until(EC.element_to_be_clickable((By.XPATH, xPath)))

Then I used the following python code with firefox and win10:

zi = e.value_of_css_property("z-index")

The webpage URL is https://irs.thsrc.com.tw/IMINT/ which has a pop-up message box.

I supposed that the z-index of this box should be one and the other elements should be zero. However, using the above python statement makes Selenium returned "auto" to all my queries. I read some people suggested that z-index query does not work for element with position value "static". So in the following page: http://aludratest.github.io/aludratest/xref/org/aludratest/service/gui/web/selenium/selenium2/ZIndexSupport.html repeated query to the "z-index" property is done until it is not "auto".
But I tried this and it results in locating failure after a few trials.

My questions are the following:

  1. Can I change the position property of the element in this case ?
  2. Will it work if I change the position property of the element ?

Thanks

Farn Wang
  • 143
  • 15

1 Answers1

1

Seems you were close. The desired element is a dynamic element so to locate the element you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • CSS_SELECTOR:

    print(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ui-dialog.ui-widget.ui-widget-content.ui-corner-all"))).value_of_css_property("z-index"))
    
  • XPATH:

    print(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='ui-dialog ui-widget ui-widget-content ui-corner-all ']"))).value_of_css_property("z-index"))
    
  • Console Output:

    1002
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks! I will try later and see if this solve my problem. But I am also using firefox in the experiment. Will that be possible if you show me how to adapt your solution for firefox. Or can I just do some simplistic substitution ? – Farn Wang Mar 23 '19 at 12:51
  • Hi, dear Debanjan: I just tried the statement EC.visibility_of_element_located(...) but did not succeed. I will appreciate if you can explain what those options are for ? Can I do those options with firefox ? Thanks – Farn Wang Mar 23 '19 at 14:34
  • @FarnWang The options were to make _Chrome_ browser maximized. I have removed them. Now the solution should work cross browser. – undetected Selenium Mar 23 '19 at 14:40
  • I tried and no luck. firefox and webdriver always returned 'auto'. Maybe it is because of firefox. I will try tomorrow and report to you. Thanks for your kind patience. – Farn Wang Mar 23 '19 at 15:08
  • Hi, dear Debanjan: I also tried Chrome and somehow the returned values are all "auto" either. I also imported the three modules that you requested. But still no luck. For Chrome the answers are still "auto". Could it be win10 ? Or python ? – Farn Wang Mar 23 '19 at 15:42