0

I was originally asking for a sort of combination for empty style and ::before css, but it seems the css is not recognizable by Selenium.

So I am posting a larger piece of the html and asking for another combination: style empty and text followed by style. Which would be style="">Full Access<

This is extended html:

<span class="highwire-citation-access highwire-citation-access-check" data-pisa-id="sci;science.aav1483" data-atom-uri="/sci/363/6422/eaav1483.atom" data-request-view="full">
<i class="highwire-access-icon highwire-access-icon-user-access user-access fa fa-unlock-alt" title="Full Access" aria-hidden="true" style=""></i>
<span class="element-invisible highwire-access-icon highwire-access-icon-user-access" style="">Full Access</span>
<i class="highwire-access-icon highwire-access-icon-no-access no-access fa fa-lock" title="Restricted Access" aria-hidden="true" style="display:none;"></i>
<span class="element-invisible highwire-access-icon highwire-access-icon-no-access" style="display:none;">Restricted Access</span></span>
<i class="highwire-access-icon highwire-access-icon-user-access user-access fa fa-unlock-alt" title="Full Access" aria-hidden="true" style=""></i>
<span class="element-invisible highwire-access-icon highwire-access-icon-user-access" style="">Full Access</span>
<i class="highwire-access-icon highwire-access-icon-no-access no-access fa fa-lock" title="Restricted Access" aria-hidden="true" style="display:none;"></i>
<span class="element-invisible highwire-access-icon highwire-access-icon-no-access" style="display:none;">Restricted Access</span>

The python relevant code:

child  = browser.find_elements(By.XPATH,(" %s" % exp))
for t in child:
    verbose = t.get_attribute('innerHTML') 

Right now the expression %s is replaced by the xpath:

 "//*[(@style='""')]/../../*"

And the results are both Full Access and Restricted Access elements.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
powerPixie
  • 718
  • 9
  • 20

2 Answers2

0

Have you tried this?

i[title="Full Access"]::before { ... }
ianrandmckenzie
  • 472
  • 3
  • 12
  • Thank you but it didn't worked. I am using python using selenium libraries. The error it returns: InvalidSelectorException: Given xpath expression " //i[title='Full Access']::before { ... }" is invalid: SyntaxError: The expression is not a legal expression. I also tested in Freeformarter webpage and it said: Unable to perform XPath operation. Unexpected token "::" beyond end of expression – powerPixie Aug 15 '19 at 10:47
  • Have you tried the selector with just plain HTML and CSS? It worked for me using W3School's "Try it" code editor. It sounds like your python package is using old CSS rules or doesn't support it. Sorry, I thought this was a CSS question, not selenium or python. – ianrandmckenzie Aug 15 '19 at 10:54
  • No problem. I just added selenium and python to the title to avoid misunderstandings. Thank you, anyway. – powerPixie Aug 15 '19 at 11:32
0

To extract the text Full Access you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//i[@class='highwire-access-icon highwire-access-icon-user-access user-access fa fa-unlock-alt' and @title='Full Access']//following::span[1]"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you, but it doesn't work. I tested it and gets me the entire list of elements again. It happens because articles with Restricted Access and Full Access have same html code, the difference is that when the element is visible the style=" " (null or empty) comes with the title (or with css ::before). I worked around treating the elements later. Like I know I got a full access article because there is a section tagged as Abstract. It's not an optimal solution but suits me for now. Thank you, anyway. – powerPixie Aug 17 '19 at 10:17