PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 26, 2022

[FIXED] How to find svg element with selenium?

 October 26, 2022     bots, instagram, python, selenium     No comments   

Issue

I'm building a python Instagram bot, and I'm trying to get it to click on the DMs icon, but I'm not sure how to select it.

I tried selecting by Xpath, but I can't seem to be able to navigate it to the icon. Here's Instagram's html code for the DMs icon:

<svg aria-label="Messenger" class="_8-yf5 " color="#262626" fill="#262626" height="24" role="img" viewBox="0 0 24 24" width="24">

Any help is appreciated.


Solution

You have to apply a slightly different locator strategy to find svg.

Here is what works:

driver.find_element(By.XPATH, "//*[name()='svg']")

assuming that this is the only svg element (as provided in your query)

Combination of more than one attribute from the same DOM line:

//*[name()='svg' and @aria-label='Messenger']


Answered By - Anand Gautam
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing