1

Does anyone know why I get this :

Z-In...Instead of Z-Index 1

Here is my code :

vid = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH,"//div[contains(@title,'Mytitle')]/div[1]/div[3]/span"))).text

print(vid)

Here is the HTML:

Here is the HTML

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Serinkan
  • 53
  • 1
  • 8
  • 1
    Post the html . – Guy Dec 18 '19 at 13:53
  • I am just wondering what you are using the `Z-Index` attribute for. – CEH Dec 18 '19 at 15:24
  • I use it on a web page with previews that I can overlap, and the Z-index is there to manage priorities, so I need them to test that there is no problem with the priorities. – Serinkan Dec 18 '19 at 15:36
  • Are you sure this isn't correct? Is the text collapased until you expand it at all? – DMart Dec 18 '19 at 17:36
  • Your example html code shows Z-Index 4, is this the right snippet to go with your question? Is there any styling done to the element? – DMart Dec 18 '19 at 17:37
  • Yes the example is Z-Index 4 but there are many others, how do I know if the text is collapased or not, and I didn't code the WebApp so I don't if there is any styling done to the element, how can I check that ? – Serinkan Dec 19 '19 at 09:56

1 Answers1

1

You need to take care of a couple of things:

  • If your usecase is to extract the value of any attribute ideally you need to use visibility_of_element_located()
  • As an alternative to text attribute you can use get_attribute() method.

Solution

As an alternative you can use the following Locator Strategy:

print(WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH,"//div[contains(@title,'Mytitle')]/div[1]/div[3]/span[starts-with(@id, 'infoZIndex')]"))).get_attribute("innerHTML"))

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

Update

As an alternative you can also try setting the expected_conditions ato text_to_be_present_in_element() as follows:

print(WebDriverWait(browser, 10).until(EC.text_to_be_present_in_element((By.XPATH,"//div[contains(@title,'Mytitle')]/div[1]/div[3]/span[starts-with(@id, 'infoZIndex')]"), "Index")).get_attribute("innerHTML"))
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Even with `visibility_of_element_located` and `get_attribute("innerHTML")` it's still the same : Z-In... – Serinkan Dec 18 '19 at 14:07
  • @Serinkan Checkout the updated answer and let me know the status. – undetected Selenium Dec 18 '19 at 14:16
  • still the same ... i don't get why he stops there and doesn't go further – Serinkan Dec 18 '19 at 14:20
  • @Serinkan Checkout the updated answer and let me know the status – undetected Selenium Dec 18 '19 at 22:47
  • I tried your last update but it doesn't work I get a TimeoutException, what is the "Index" for ? ```(@id, 'infoZIndex')]"), "Index")) ```? And I really appreciate your help. – Serinkan Dec 19 '19 at 09:52
  • @Serinkan `Index` is the partial text of the innerText **Z-Index 1** which you are looking to extract. – undetected Selenium Dec 19 '19 at 09:55
  • I get an empty error message ```Message:```, is it really empty or it's just hidden ? – Serinkan Dec 19 '19 at 10:03
  • `vid1 = WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH,"//div[contains(@title,'MyTitle')]"))).get_attribute("id")` `try: print(WebDriverWait(browser, 10).until(EC.text_to_be_present_in_element((By.XPATH,"//div[contains(@title,'MyTitle')]/div[1]/div[3]/span[@id,'infoZIndex" + vid1 +"']"), "Z-Index")).get_attribute("innerHTML")) except TimeoutException as e: print(e)` I tried this with getting the Id on the upper div wich is equal to infoZIndex + Id, im pretty sure it's the right element – Serinkan Dec 19 '19 at 11:07
  • I checked the id of the span and the id of the ("infoZIndex" + div ID)if they were equal `infoZIndex9897724 / infoZIndex9897724` – Serinkan Dec 19 '19 at 11:22
  • 1
    I found why it didn't work. The Z-Index wasn't fully displayed on screen, but I don't understand because I took it from the span which has nothing to do with the displayed information. And thank you for your help. – Serinkan Dec 19 '19 at 15:21
  • @Serinkan Huge relief for me :) I thought from many angles about the reason. Glad you found it out. – undetected Selenium Dec 19 '19 at 15:23