Home > Software engineering >  Get value from pseudo element with python
Get value from pseudo element with python

Time:02-08

I would like to get the price value from the pseudo element you see on the picture below. If I hover over the mouse only then I can see some value like the price it costs( that is what I need). I found the "move_to_element" so now I can hover over the mouse with the program but I still cant get the price out of the element. The problem is that even if I hover over my mouse I cant see the element opening in the inspector tab.

Thank you! enter image description here

This is the code I would like to get out the :before element from:

<div onclick="Game.UpgradesById[503].click(event);"  onm ouseout="Game.setOnCrate(0);Game.tooltip.shouldHide=1;" onm ouseover="if (!Game.mouseDown) {Game.setOnCrate(this);Game.tooltip.dynamic=1;Game.tooltip.draw(this,function(){return function(){return Game.crateTooltip(Game.UpgradesById[503],'store');}();},'store');Game.tooltip.wobble();}" id="upgrade0" style="background-position:-1056px -1296px;"></div>

After this there is an en element ::before and end of the div

CodePudding user response:

When I visited the website manually, I get somewhat like what you showed, but when I run through automation, it does not show any Upgrades. Hence, I had to stick to checking the identities (like Grandma, Cursor, etc); but they didn't show in automated version. Only the users ??? are seen. Snapshot

Eventually, I tried it with ??? only. I tried a different approach, instead of using ::before or ::after, I tried to see if any tooltip exists somewhere, and it does exist. The only caveat is that I was able to fetch all the text from the hover (from which again we have to extract what is required through code). On this context, here is the code:

driver.get("https://orteil.dashnet.org/cookieclicker/")
time.sleep(10)
ActionChains(driver).move_to_element(driver.find_element(By.ID, 'product0')).perform()
time.sleep(1)
x = driver.find_element(By.ID, 'tooltip').text
print(x)

Here is the output:

15
???
[owned : 0]

Process finished with exit code 0

Please change the element to the element that you want and you should get the result.

  •  Tags:  
  • Related